mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 01:26:14 +08:00
![Sam](/assets/img/avatar_default.png)
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.
36 lines
808 B
JavaScript
36 lines
808 B
JavaScript
import { registerOption } from 'pretty-text/pretty-text';
|
|
|
|
function tableFlattenBlocks(blocks) {
|
|
let result = "";
|
|
|
|
blocks.forEach(b => {
|
|
result += b;
|
|
if (b.trailing) { result += b.trailing; }
|
|
});
|
|
|
|
// bypass newline insertion
|
|
return result.replace(/[\n\r]/g, " ");
|
|
};
|
|
|
|
registerOption((siteSettings, opts) => {
|
|
opts.features.table = !!siteSettings.allow_html_tables;
|
|
});
|
|
|
|
export function setup(helper) {
|
|
|
|
if (helper.markdownIt) { return; }
|
|
|
|
helper.whiteList(['table', 'table.md-table', 'tbody', 'thead', 'tr', 'th', 'td']);
|
|
|
|
helper.replaceBlock({
|
|
start: /(<table[^>]*>)([\S\s]*)/igm,
|
|
stop: /<\/table>/igm,
|
|
rawContents: true,
|
|
priority: 1,
|
|
|
|
emitter(contents) {
|
|
return ['table', {"class": "md-table"}, tableFlattenBlocks.apply(this, [contents])];
|
|
}
|
|
});
|
|
}
|