// 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 (outHref.lastIndexOf('http', 0) !== 0) { outHref = `http://${outHref}`; } let output = ''; return output; } paragraph(text) { if (this.formattingOptions.singleline) { return `

${text}

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