diff --git a/plugins/discourse-details/config/locales/server.en.yml b/plugins/discourse-details/config/locales/server.en.yml index 80264438ca3..36bed99116f 100644 --- a/plugins/discourse-details/config/locales/server.en.yml +++ b/plugins/discourse-details/config/locales/server.en.yml @@ -1,3 +1,5 @@ en: site_settings: details_enabled: "Enable the details feature. If you change this, you must rebake all posts with: \"rake posts:rebake\"." + details: + excerpt_details: "(click for more details)" diff --git a/plugins/discourse-details/plugin.rb b/plugins/discourse-details/plugin.rb index 78f78e7a66a..68daecbd2c5 100644 --- a/plugins/discourse-details/plugin.rb +++ b/plugins/discourse-details/plugin.rb @@ -31,8 +31,14 @@ after_initialize do end end - on(:reduce_cooked) do |fragment| - fragment.css("details.elided").each(&:remove) + on(:reduce_cooked) do |fragment, post| + fragment.css("details").each do |el| + text = fragment.css("summary").text + link = fragment.document.create_element("a") + link["href"] = post.url if post + link.content = I18n.t("details.excerpt_details") + el.replace text + " " + link.to_html + end end end diff --git a/plugins/discourse-details/spec/components/pretty_text_spec.rb b/plugins/discourse-details/spec/components/pretty_text_spec.rb index bd911739b6f..946d56cf778 100644 --- a/plugins/discourse-details/spec/components/pretty_text_spec.rb +++ b/plugins/discourse-details/spec/components/pretty_text_spec.rb @@ -5,6 +5,8 @@ require 'pretty_text' describe PrettyText do + let(:post) { Fabricate(:post) } + it "supports details tag" do cooked_html = <<~HTML
@@ -20,9 +22,23 @@ describe PrettyText do it "deletes elided content" do cooked_html = PrettyText.cook("Hello World\n\n
42
") - mail_html = PrettyText.cook("Hello World") + mail_html = "

Hello World

\n(click for more details)" expect(PrettyText.format_for_email(cooked_html)).to match_html(mail_html) end + it 'can replace spoilers in emails' do + md = PrettyText.cook(<<~EOF) + hello + + [details="Summary"] + world + [/details] + EOF + md = PrettyText.format_for_email(md, post) + html = "

hello

\n\nSummary (click for more details)" + + expect(md).to eq(html) + end + end