// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. const TextFormatting = require('./text_formatting.jsx'); const Utils = require('./utils.jsx'); const marked = require('marked'); 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]+?(?=[\\${text}`; } link(href, title, text) { let outHref = href; if (!(/^(mailto|https?|ftp)/.test(outHref))) { outHref = `http://${outHref}`; } let output = ''; return output; } paragraph(text) { let outText = text; // required so markdown does not strip '_' from @user_names outText = TextFormatting.doFormatMentions(text); if (!('emoticons' in this.options) || this.options.emoticon) { outText = TextFormatting.doFormatEmoticons(outText); } if (this.formattingOptions.singleline) { return `

${outText}

`; } return super.paragraph(outText); } table(header, body) { return `${header}${body}
`; } text(txt) { 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); }