discourse/plugins/discourse-details/assets/javascripts/lib/discourse-markdown/details.js
Joffrey JAFFEUX fd15562939
FIX: allows to use open attribute with details (#29116)
Supporting `open` allows to show a `details` block open by default.

Usage:

```
[details open]
my visible content
[/details]
```
2024-10-08 11:13:44 +09:00

36 lines
735 B
JavaScript

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