summaryrefslogtreecommitdiffstats
path: root/web/react/utils/markdown.jsx
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-09-23 12:55:58 -0700
committer=Corey Hulen <corey@hulen.com>2015-09-23 12:55:58 -0700
commit2b5b8f95ed9de37a15dc68c38c46a1da2bb1e160 (patch)
treed5bf8318dc82d96cd34b83481e1cc5c8289d170a /web/react/utils/markdown.jsx
parent9e04909c0a3672d27c148c931d82b225cc86dfe5 (diff)
parent0170cfe604e6cfb430be0b6181243ca85a9ab27b (diff)
downloadchat-2b5b8f95ed9de37a15dc68c38c46a1da2bb1e160.tar.gz
chat-2b5b8f95ed9de37a15dc68c38c46a1da2bb1e160.tar.bz2
chat-2b5b8f95ed9de37a15dc68c38c46a1da2bb1e160.zip
Merge branch 'master' into PLT-11-email
Diffstat (limited to 'web/react/utils/markdown.jsx')
-rw-r--r--web/react/utils/markdown.jsx26
1 files changed, 25 insertions, 1 deletions
diff --git a/web/react/utils/markdown.jsx b/web/react/utils/markdown.jsx
index 96da54217..347024e1a 100644
--- a/web/react/utils/markdown.jsx
+++ b/web/react/utils/markdown.jsx
@@ -1,9 +1,25 @@
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
+const TextFormatting = require('./text_formatting.jsx');
+
const marked = require('marked');
export class MattermostMarkdownRenderer extends marked.Renderer {
+ constructor(options, formattingOptions = {}) {
+ super(options);
+
+ this.heading = this.heading.bind(this);
+ this.text = this.text.bind(this);
+
+ this.formattingOptions = formattingOptions;
+ }
+
+ heading(text, level, raw) {
+ const id = `${this.options.headerPrefix}${raw.toLowerCase().replace(/[^\w]+/g, '-')}`;
+ return `<h${level} id="${id}" class="markdown__heading">${text}</h${level}>`;
+ }
+
link(href, title, text) {
let outHref = href;
@@ -11,7 +27,7 @@ export class MattermostMarkdownRenderer extends marked.Renderer {
outHref = `http://${outHref}`;
}
- let output = '<a class="theme" href="' + outHref + '"';
+ let output = '<a class="theme markdown__link" href="' + outHref + '"';
if (title) {
output += ' title="' + title + '"';
}
@@ -19,4 +35,12 @@ export class MattermostMarkdownRenderer extends marked.Renderer {
return output;
}
+
+ table(header, body) {
+ return `<table class="markdown__table"><thead>${header}</thead><tbody>${body}</tbody></table>`;
+ }
+
+ text(text) {
+ return TextFormatting.doFormatText(text, this.formattingOptions);
+ }
}