Skip to content

A platform for community discussion. Free, open, simple.

FIX: Replace details content with instruction.

Bianca Nenciu3a1d99577e4e
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
<details>
@@ -20,9 +22,23 @@ describe PrettyText do
it "deletes elided content" do
cooked_html = PrettyText.cook("Hello World\n\n<details class='elided'>42</details>")
- mail_html = PrettyText.cook("Hello World")
+ mail_html = "<p>Hello World</p>\n<a href=\"http://test.localhost\">(click for more details)</a>"
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 = "<p>hello</p>\n\nSummary <a href=\"#{post.full_url}\">(click for more details)</a>"
+
+ expect(md).to eq(html)
+ end
+
end