From c868620693c69e2931c3023460eaafd9f6d330b6 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 19 May 2016 08:38:50 -0400 Subject: Updated our fork of marked and added more links to test-links.md (#3047) --- webapp/utils/markdown.jsx | 52 +++-------------------------------------------- 1 file changed, 3 insertions(+), 49 deletions(-) (limited to 'webapp/utils') diff --git a/webapp/utils/markdown.jsx b/webapp/utils/markdown.jsx index 2ddd3fe11..69b18faee 100644 --- a/webapp/utils/markdown.jsx +++ b/webapp/utils/markdown.jsx @@ -13,40 +13,6 @@ function markdownImageLoaded(image) { } window.markdownImageLoaded = markdownImageLoaded; -class MattermostInlineLexer extends marked.InlineLexer { - constructor(links, options) { - super(links, options); - - this.rules = Object.assign({}, this.rules); - - // modified version of the regex that allows for links starting with www and those surrounded by parentheses - // the original is /^[\s\S]+?(?=[\\ starting with www. - // the original is /^<([^ >]+(@|:\/)[^ >]+)>/ - this.rules.autolink = /^<((?:[^ >]+(@|:\/)|www\.)[^ >]+)>/; - } -} - -class MattermostParser extends marked.Parser { - parse(src) { - this.inline = new MattermostInlineLexer(src.links, this.options, this.renderer); - this.tokens = src.reverse(); - - var out = ''; - while (this.next()) { - out += this.tok(); - } - - return out; - } -} - class MattermostMarkdownRenderer extends marked.Renderer { constructor(options, formattingOptions = {}) { super(options); @@ -109,18 +75,6 @@ class MattermostMarkdownRenderer extends marked.Renderer { link(href, title, text) { let outHref = href; - let outText = text; - let prefix = ''; - let suffix = ''; - - // some links like https://en.wikipedia.org/wiki/Rendering_(computer_graphics) contain brackets - // and we try our best to differentiate those from ones just wrapped in brackets when autolinking - if (outHref.startsWith('(') && outHref.endsWith(')') && text === outHref) { - prefix = '('; - suffix = ')'; - outText = text.substring(1, text.length - 1); - outHref = outHref.substring(1, outHref.length - 1); - } try { const unescaped = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, '').toLowerCase(); @@ -149,9 +103,9 @@ class MattermostMarkdownRenderer extends marked.Renderer { output += ' title="' + title + '"'; } - output += '>' + outText + ''; + output += '>' + text + ''; - return prefix + output + suffix; + return output; } paragraph(text) { @@ -486,7 +440,7 @@ export function format(text, options) { const tokens = new MattermostLexer(markdownOptions).lex(text); - return new MattermostParser(markdownOptions).parse(tokens); + return new marked.Parser(markdownOptions).parse(tokens); } // Marked helper functions that should probably just be exported -- cgit v1.2.3-1-g7c22