Merge pull request #987 from hmhealey/plt521
PLT-521 Modified markdown lexer to not break up words written in snake_case
Этот коммит содержится в:
@@ -6,7 +6,31 @@ const Utils = require('./utils.jsx');
|
|||||||
|
|
||||||
const marked = require('marked');
|
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 = {}) {
|
constructor(options, formattingOptions = {}) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
@@ -68,3 +92,15 @@ export class MattermostMarkdownRenderer extends marked.Renderer {
|
|||||||
return TextFormatting.doFormatText(text, this.formattingOptions);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ const Markdown = require('./markdown.jsx');
|
|||||||
const UserStore = require('../stores/user_store.jsx');
|
const UserStore = require('../stores/user_store.jsx');
|
||||||
const Utils = require('./utils.jsx');
|
const Utils = require('./utils.jsx');
|
||||||
|
|
||||||
const marked = require('marked');
|
|
||||||
|
|
||||||
// Performs formatting of user posts including highlighting mentions and search terms and converting urls, hashtags, and
|
// Performs formatting of user posts including highlighting mentions and search terms and converting urls, hashtags, and
|
||||||
// @mentions to links by taking a user's message and returning a string of formatted html. Also takes a number of options
|
// @mentions to links by taking a user's message and returning a string of formatted html. Also takes a number of options
|
||||||
// as part of the second parameter:
|
// as part of the second parameter:
|
||||||
@@ -22,11 +20,8 @@ export function formatText(text, options = {}) {
|
|||||||
let output;
|
let output;
|
||||||
|
|
||||||
if (!('markdown' in options) || options.markdown) {
|
if (!('markdown' in options) || options.markdown) {
|
||||||
// the markdown renderer will call doFormatText as necessary so just call marked
|
// the markdown renderer will call doFormatText as necessary
|
||||||
output = marked(text, {
|
output = Markdown.format(text, options);
|
||||||
renderer: new Markdown.MattermostMarkdownRenderer(null, options),
|
|
||||||
sanitize: true
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
output = sanitizeHtml(text);
|
output = sanitizeHtml(text);
|
||||||
output = doFormatText(output, options);
|
output = doFormatText(output, options);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user