mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 21:45:58 +08:00
fd15562939
Supporting `open` allows to show a `details` block open by default. Usage: ``` [details open] my visible content [/details] ```
112 lines
2.6 KiB
Ruby
112 lines
2.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "pretty_text"
|
|
|
|
RSpec.describe PrettyText do
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
it "supports details tag" do
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
[details="foo"]
|
|
bar
|
|
[/details]
|
|
MARKDOWN
|
|
|
|
expect(cooked_html).to match_html <<~HTML
|
|
<details>
|
|
<summary>foo</summary>
|
|
<p>bar</p>
|
|
</details>
|
|
HTML
|
|
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
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
Hello World
|
|
|
|
<details class='elided'>42</details>
|
|
MARKDOWN
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html)
|
|
|
|
expect(email_html).to match_html <<~HTML
|
|
<p>Hello World</p>
|
|
<a href="#{Discourse.base_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
HTML
|
|
end
|
|
|
|
it "can replace spoilers in emails" do
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
hello
|
|
|
|
[details="Summary"]
|
|
world
|
|
[/details]
|
|
MARKDOWN
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html, post)
|
|
|
|
expect(email_html).to match_html <<~HTML
|
|
<p>hello</p>
|
|
Summary <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
HTML
|
|
end
|
|
|
|
it "properly handles multiple spoiler blocks in a post" do
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
[details="First"]
|
|
body secret stuff very long
|
|
[/details]
|
|
[details="Second"]
|
|
body secret stuff very long
|
|
[/details]
|
|
|
|
Hey there.
|
|
|
|
[details="Third"]
|
|
body secret stuff very long
|
|
[/details]
|
|
MARKDOWN
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html, post)
|
|
|
|
expect(email_html).to match_html <<~HTML
|
|
First <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
Second <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
<p>Hey there.</p>
|
|
Third <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
HTML
|
|
end
|
|
|
|
it "escapes summary text" do
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
<script>alert('hello')</script>
|
|
|
|
[details="<script>alert('hello')</script>"]
|
|
<script>alert('hello')</script>
|
|
[/details]
|
|
MARKDOWN
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html, post)
|
|
|
|
expect(email_html).to match_html <<~HTML
|
|
<script>alert('hello')</script> <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
HTML
|
|
end
|
|
end
|