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]
```
This commit is contained in:
Joffrey JAFFEUX 2024-10-08 11:13:44 +09:00 committed by GitHub
parent 85774cc214
commit fd15562939
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -2,9 +2,13 @@ const rule = {
tag: "details", tag: "details",
before(state, tagInfo) { before(state, tagInfo) {
const attrs = tagInfo.attrs; const attrs = tagInfo.attrs;
state.push("bbcode_open", "details", 1); const details = state.push("bbcode_open", "details", 1);
state.push("bbcode_open", "summary", 1); state.push("bbcode_open", "summary", 1);
if (attrs.open === "") {
details.attrs = [["open", ""]];
}
let token = state.push("text", "", 0); let token = state.push("text", "", 0);
token.content = attrs["_default"] || ""; token.content = attrs["_default"] || "";

View File

@ -20,10 +20,25 @@ RSpec.describe PrettyText do
HTML HTML
end end
it "supports open attribute" do
cooked_html = PrettyText.cook <<~MARKDOWN
[details open]
bar
[/details]
MARKDOWN
expect(cooked_html).to match_html <<~HTML
<details open="">
<summary></summary>
<p>bar</p>
</details>
HTML
end
it "deletes elided content" do it "deletes elided content" do
cooked_html = PrettyText.cook <<~MARKDOWN cooked_html = PrettyText.cook <<~MARKDOWN
Hello World Hello World
<details class='elided'>42</details> <details class='elided'>42</details>
MARKDOWN MARKDOWN