diff --git a/plugins/discourse-details/assets/javascripts/lib/discourse-markdown/details.js b/plugins/discourse-details/assets/javascripts/lib/discourse-markdown/details.js index 00bd6b670a5..028b9e9bcdf 100644 --- a/plugins/discourse-details/assets/javascripts/lib/discourse-markdown/details.js +++ b/plugins/discourse-details/assets/javascripts/lib/discourse-markdown/details.js @@ -2,9 +2,13 @@ const rule = { tag: "details", before(state, tagInfo) { const attrs = tagInfo.attrs; - state.push("bbcode_open", "details", 1); + 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"] || ""; diff --git a/plugins/discourse-details/spec/components/pretty_text_spec.rb b/plugins/discourse-details/spec/components/pretty_text_spec.rb index cf1e87e6011..28b8b67cc1e 100644 --- a/plugins/discourse-details/spec/components/pretty_text_spec.rb +++ b/plugins/discourse-details/spec/components/pretty_text_spec.rb @@ -20,10 +20,25 @@ RSpec.describe PrettyText do HTML end + it "supports open attribute" do + cooked_html = PrettyText.cook <<~MARKDOWN + [details open] + bar + [/details] + MARKDOWN + + expect(cooked_html).to match_html <<~HTML +
+ +

bar

+
+ HTML + end + it "deletes elided content" do cooked_html = PrettyText.cook <<~MARKDOWN Hello World - +
42
MARKDOWN