2016-06-15 02:31:51 +08:00
|
|
|
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) {
|
|
|
|
|
2017-06-09 06:02:30 +08:00
|
|
|
if (helper.markdownIt) { return; }
|
|
|
|
|
2016-06-15 02:31:51 +08:00
|
|
|
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])];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|