summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-09-22 14:34:59 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-09-22 14:34:59 -0400
commit55f11ba8719d133103bc1d4779bb8cb66d591b58 (patch)
tree4405b4f79b3534749e57f6a4ad092349a895a15d /web
parent1afa1d37c77b9508a4256e32c4e1fea27113033f (diff)
downloadchat-55f11ba8719d133103bc1d4779bb8cb66d591b58.tar.gz
chat-55f11ba8719d133103bc1d4779bb8cb66d591b58.tar.bz2
chat-55f11ba8719d133103bc1d4779bb8cb66d591b58.zip
Removed extra handling of markdown links when doing autolinking
Diffstat (limited to 'web')
-rw-r--r--web/react/utils/text_formatting.jsx36
1 files changed, 5 insertions, 31 deletions
diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx
index 41dc98084..56bf49c3f 100644
--- a/web/react/utils/text_formatting.jsx
+++ b/web/react/utils/text_formatting.jsx
@@ -19,13 +19,9 @@ const marked = require('marked');
// - emoticons - Enables emoticon parsing. Defaults to true.
// - markdown - Enables markdown parsing. Defaults to true.
export function formatText(text, options = {}) {
- if (!('markdown' in options)) {
- options.markdown = true;
- }
-
let output;
- if (options.markdown) {
+ if (!('markdown' in options) || options.markdown) {
// the markdown renderer will call doFormatText as necessary so just call marked
output = marked(text, {
renderer: new Markdown.MattermostMarkdownRenderer(null, options),
@@ -44,13 +40,14 @@ export function formatText(text, options = {}) {
return output;
}
+// Performs most of the actual formatting work for formatText. Not intended to be called normally.
export function doFormatText(text, options) {
let output = text;
const tokens = new Map();
// replace important words and phrases with tokens
- output = autolinkUrls(output, tokens, !!options.markdown);
+ output = autolinkUrls(output, tokens);
output = autolinkAtMentions(output, tokens);
output = autolinkHashtags(output, tokens);
@@ -85,7 +82,7 @@ export function sanitizeHtml(text) {
return output;
}
-function autolinkUrls(text, tokens, markdown) {
+function autolinkUrls(text, tokens) {
function replaceUrlWithToken(autolinker, match) {
const linkText = match.getMatchedText();
let url = linkText;
@@ -115,30 +112,7 @@ function autolinkUrls(text, tokens, markdown) {
replaceFn: replaceUrlWithToken
});
- let output = text;
-
- // temporarily replace markdown links if markdown is enabled so that we don't accidentally parse them twice
- const markdownLinkTokens = new Map();
- if (markdown) {
- function replaceMarkdownLinkWithToken(markdownLink) {
- const index = markdownLinkTokens.size;
- const alias = `MM_MARKDOWNLINK${index}`;
-
- markdownLinkTokens.set(alias, {value: markdownLink});
-
- return alias;
- }
-
- output = output.replace(/\]\([^\)]*\)/g, replaceMarkdownLinkWithToken);
- }
-
- output = autolinker.link(output);
-
- if (markdown) {
- output = replaceTokens(output, markdownLinkTokens);
- }
-
- return output;
+ return autolinker.link(text);
}
function autolinkAtMentions(text, tokens) {