discourse/plugins/discourse-details/assets/javascripts/lib/discourse-markdown/details.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
735 B
JavaScript
Raw Normal View History

const rule = {
2018-06-16 00:42:20 +08:00
tag: "details",
before(state, tagInfo) {
2017-07-22 04:16:07 +08:00
const attrs = tagInfo.attrs;
const details = state.push("bbcode_open", "details", 1);
2018-06-16 00:42:20 +08:00
state.push("bbcode_open", "summary", 1);
if (attrs.open === "") {
details.attrs = [["open", ""]];
}
2018-06-16 00:42:20 +08:00
let token = state.push("text", "", 0);
token.content = attrs["_default"] || "";
2018-06-16 00:42:20 +08:00
state.push("bbcode_close", "summary", -1);
},
after(state) {
2018-06-16 00:42:20 +08:00
state.push("bbcode_close", "details", -1);
},
};
export function setup(helper) {
helper.allowList([
2018-06-16 00:42:20 +08:00
"summary",
"summary[title]",
"details",
"details[open]",
"details.elided",
]);
helper.registerPlugin((md) => {
2018-06-16 00:42:20 +08:00
md.block.bbcode.ruler.push("details", rule);
});
}