Cleaned up markdown formatting code and removed debug statements
Этот коммит содержится в:
@@ -5,10 +5,12 @@ const marked = require('marked');
|
|||||||
|
|
||||||
export class MattermostMarkdownRenderer extends marked.Renderer {
|
export class MattermostMarkdownRenderer extends marked.Renderer {
|
||||||
link(href, title, text) {
|
link(href, title, text) {
|
||||||
if (href.lastIndexOf('http', 0) !== 0) {
|
let outHref = href;
|
||||||
href = `http://${href}`;
|
|
||||||
|
if (outHref.lastIndexOf('http', 0) !== 0) {
|
||||||
|
outHref = `http://${outHref}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.link(href, title, text);
|
return super.link(outHref, title, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ const markdownRenderer = new Markdown.MattermostMarkdownRenderer();
|
|||||||
// - searchTerm - If specified, this word is highlighted in the resulting html. Defaults to nothing.
|
// - searchTerm - If specified, this word is highlighted in the resulting html. Defaults to nothing.
|
||||||
// - mentionHighlight - Specifies whether or not to highlight mentions of the current user. Defaults to true.
|
// - mentionHighlight - Specifies whether or not to highlight mentions of the current user. Defaults to true.
|
||||||
// - singleline - Specifies whether or not to remove newlines. Defaults to false.
|
// - singleline - Specifies whether or not to remove newlines. Defaults to false.
|
||||||
|
// - markdown - Enables markdown parsing. Defaults to true.
|
||||||
export function formatText(text, options = {}) {
|
export function formatText(text, options = {}) {
|
||||||
// TODO remove me
|
if (!('markdown' in options)) {
|
||||||
options.markdown = true;
|
options.markdown = true;
|
||||||
|
}
|
||||||
|
|
||||||
// wait until marked can sanitize the html so that we don't break markdown block quotes
|
// wait until marked can sanitize the html so that we don't break markdown block quotes
|
||||||
let output;
|
let output;
|
||||||
@@ -46,12 +48,10 @@ export function formatText(text, options = {}) {
|
|||||||
|
|
||||||
// perform markdown parsing while we have an html-free input string
|
// perform markdown parsing while we have an html-free input string
|
||||||
if (options.markdown) {
|
if (options.markdown) {
|
||||||
console.log('output before marked ' + output);
|
|
||||||
output = marked(output, {
|
output = marked(output, {
|
||||||
renderer: markdownRenderer,
|
renderer: markdownRenderer,
|
||||||
sanitize: true
|
sanitize: true
|
||||||
});
|
});
|
||||||
console.log('output after marked ' + output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reinsert tokens with formatted versions of the important words and phrases
|
// reinsert tokens with formatted versions of the important words and phrases
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user