discourse/plugins/footnote/spec/pretty_text_spec.rb
Ted Johansson d0915027a8
DEV: Remove deprecated queue_jobs site setting (#24127)
Using SiteSetting.queue_jobs= to configure job asynchronicity was deprecated here four years ago and marked for removal in version 2.9.0. This PR removes the fallback method we kept since then. The method was there because it was still being used in a bunch of plugin tests (now fixed.)
2023-10-27 11:05:02 +08:00

109 lines
3.2 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
describe PrettyText do
before { Jobs.run_immediately! }
it "can be disabled" do
SiteSetting.enable_markdown_footnotes = false
markdown = <<~MD
Here is a footnote, [^1]
[^1]: I am one
MD
html = <<~HTML
<p>Here is a footnote, [^1]</p>\n<p>[^1]: I am one</p>
HTML
cooked = PrettyText.cook markdown.strip
expect(cooked).to eq(html.strip)
end
it "supports normal footnotes" do
markdown = <<~MD
Here is a footnote, [^1] and another. [^test]
[^1]: I am one
[^test]: I am one
test multiline
MD
html = <<~HTML
<p>Here is a footnote, <sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> and another. <sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup></p>
<p>test multiline</p>
<hr class="footnotes-sep">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p>I am one <a href="#fnref1" class="footnote-backref"></a></p>
</li>
<li id="fn2" class="footnote-item"><p>I am one <a href="#fnref2" class="footnote-backref">↩︎</a></p>
</li>
</ol>
HTML
cooked = PrettyText.cook markdown.strip
expect(cooked).to eq(html.strip)
end
it "applies unique ids to elements after cooking a post" do
raw = <<~MD
Here is a footnote, [^1] and another. [^test]
[^1]: I am one
[^test]: I am one
test multiline
MD
post = create_post(raw: raw)
post.reload
html = <<~HTML
<p>Here is a footnote, <sup class="footnote-ref"><a href="#footnote-#{post.id}-1" id="footnote-ref-#{post.id}-1">[1]</a></sup> and another. <sup class="footnote-ref"><a href="#footnote-#{post.id}-2" id="footnote-ref-#{post.id}-2">[2]</a></sup></p>
<p>test multiline</p>
<hr class="footnotes-sep">
<ol class="footnotes-list">
<li id="footnote-#{post.id}-1" class="footnote-item"><p>I am one <a href="#footnote-ref-#{post.id}-1" class="footnote-backref">↩︎</a></p>
</li>
<li id="footnote-#{post.id}-2" class="footnote-item"><p>I am one <a href="#footnote-ref-#{post.id}-2" class="footnote-backref"></a></p>
</li>
</ol>
HTML
expect(post.cooked.strip).to eq(html.strip)
end
it "supports inline footnotes wrapped in <a> elements by ending the elements early" do
raw = <<~MD
I have a point, see footnote. <a>^[the point]</a>
<a>^[footnote]</a>
MD
post = create_post(raw: raw)
post.reload
html = <<~HTML
<p>I have a point, see footnote. <a></a><sup class="footnote-ref"><a href="#footnote-#{post.id}-1" id="footnote-ref-#{post.id}-1">[1]</a></sup></p>
<p><a></a><sup class="footnote-ref"><a href="#footnote-#{post.id}-2" id="footnote-ref-#{post.id}-2">[2]</a></sup></p>
<hr class="footnotes-sep">
<ol class="footnotes-list">
<li id="footnote-#{post.id}-1" class="footnote-item"><p>the point <a href="#footnote-ref-#{post.id}-1" class="footnote-backref"></a></p>
</li>
<li id="footnote-#{post.id}-2" class="footnote-item"><p>footnote <a href="#footnote-ref-#{post.id}-2" class="footnote-backref">↩︎</a></p>
</li>
</ol>
HTML
expect(post.cooked.strip).to eq(html.strip)
end
end