mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
234694b50f
This adds the markdown.it engine to Discourse. https://github.com/markdown-it/markdown-it As the migration is going to take a while the new engine is default disabled. To enable it you must change the hidden site setting: enable_experimental_markdown_it. This commit is a squash of many other commits, it also includes some improvements to autospec (ability to run plugins), and a dev dependency on the og gem for html normalization.
31 lines
964 B
JavaScript
31 lines
964 B
JavaScript
// Support for the newline behavior in markdown that most expect. Look through all text nodes
|
|
// in the tree, replace any new lines with `br`s.
|
|
|
|
export function setup(helper) {
|
|
|
|
if (helper.markdownIt) { return; }
|
|
|
|
helper.postProcessText((text, event) => {
|
|
const { options, insideCounts } = event;
|
|
if (options.traditionalMarkdownLinebreaks || (insideCounts.pre > 0)) { return; }
|
|
|
|
if (text === "\n") {
|
|
// If the tag is just a new line, replace it with a `<br>`
|
|
return [['br']];
|
|
} else {
|
|
// If the text node contains new lines, perhaps with text between them, insert the
|
|
// `<br>` tags.
|
|
const split = text.split(/\n+/);
|
|
if (split.length) {
|
|
const replacement = [];
|
|
for (var i=0; i<split.length; i++) {
|
|
if (split[i].length > 0) { replacement.push(split[i]); }
|
|
if (i !== split.length-1) { replacement.push(['br']); }
|
|
}
|
|
|
|
return replacement;
|
|
}
|
|
}
|
|
});
|
|
}
|