discourse/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown/table.js

Failed to ignore revisions in .git-blame-ignore-revs.

41 lines
775 B
JavaScript
Raw Normal View History

export function setup(helper) {
helper.registerPlugin(md => {
2018-06-15 23:03:24 +08:00
md.renderer.rules.table_open = function() {
2017-11-13 15:09:24 +08:00
return '<div class="md-table">\n<table>\n';
};
2018-06-15 23:03:24 +08:00
md.renderer.rules.table_close = function() {
return "</table>\n</div>";
};
});
// we need a custom callback for style handling
helper.whiteList({
2018-06-15 23:03:24 +08:00
custom: function(tag, attr, val) {
if (tag !== "th" && tag !== "td") {
return false;
}
2018-06-15 23:03:24 +08:00
if (attr !== "style") {
return false;
}
2018-06-15 23:03:24 +08:00
return (
val === "text-align:right" ||
val === "text-align:left" ||
val === "text-align:center"
);
}
});
helper.whiteList([
2018-06-15 23:03:24 +08:00
"table",
"tbody",
"thead",
"tr",
"th",
"td",
"div.md-table"
]);
}