summaryrefslogtreecommitdiffstats
path: root/web/react/utils/markdown.jsx
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-10-08 18:18:51 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-10-28 14:31:41 -0400
commit429e25864b86b7b5976348860a302c2843687ef4 (patch)
tree328e00eef5cbe96534960c80afc74c3c2e498002 /web/react/utils/markdown.jsx
parentccf9e0cabd9fcede118ca54b24adb33c788a7ae9 (diff)
downloadchat-429e25864b86b7b5976348860a302c2843687ef4.tar.gz
chat-429e25864b86b7b5976348860a302c2843687ef4.tar.bz2
chat-429e25864b86b7b5976348860a302c2843687ef4.zip
Modified markdown lexer to not break up words written in snake_case
Diffstat (limited to 'web/react/utils/markdown.jsx')
-rw-r--r--web/react/utils/markdown.jsx38
1 files changed, 37 insertions, 1 deletions
diff --git a/web/react/utils/markdown.jsx b/web/react/utils/markdown.jsx
index 26587dd6e..4fb4c6089 100644
--- a/web/react/utils/markdown.jsx
+++ b/web/react/utils/markdown.jsx
@@ -6,7 +6,31 @@ const Utils = require('./utils.jsx');
const marked = require('marked');
-export class MattermostMarkdownRenderer extends marked.Renderer {
+class MattermostInlineLexer extends marked.InlineLexer {
+ constructor(links, options) {
+ super(links, options);
+
+ // modified version of the regex that doesn't break up words in snake_case
+ // the original is /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
+ this.rules.text = /^[\s\S]+?(?=__|\b_|[\\<!\[*`]| {2,}\n|$)/;
+ }
+}
+
+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);
@@ -78,3 +102,15 @@ export class MattermostMarkdownRenderer extends marked.Renderer {
return TextFormatting.doFormatText(txt, this.formattingOptions);
}
}
+
+export function format(text, options) {
+ const markdownOptions = {
+ renderer: new MattermostMarkdownRenderer(null, options),
+ sanitize: true
+ };
+
+ const tokens = marked.lexer(text, markdownOptions);
+
+ return new MattermostParser(markdownOptions).parse(tokens);
+}
+