discourse-math/spec/pretty_text_spec.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "rails_helper"
2017-07-06 16:50:38 -04:00
describe PrettyText do
context "with discourse math" do
before { SiteSetting.discourse_math_enabled = true }
2017-07-06 16:50:38 -04:00
it "can handle inline math" do
2017-07-18 14:40:05 -04:00
cooked = PrettyText.cook('I like $\{a,b\}\$<a>$ etc')
html = '<p>I like <span class="math">\{a,b\}\$&lt;a&gt;</span> etc</p>'
2017-07-06 16:50:38 -04:00
expect(cooked).to eq(html)
end
it "can correctly ignore bad blocks" do
2017-07-06 16:50:38 -04:00
cooked = PrettyText.cook <<~MD
$$a
a
$$"
MD
html = <<~HTML
<p>$$a<br>
a<br>
$$"</p>
HTML
expect(cooked).to eq(html.strip)
end
it "can handle inline edge cases" do
expect(PrettyText.cook ",$+500\\$").not_to include("math")
expect(PrettyText.cook "$+500$").to include("math")
expect(PrettyText.cook ",$+500$,").to include("math")
expect(PrettyText.cook "200$ + 500$").not_to include("math")
expect(PrettyText.cook ",$+500$x").not_to include("math")
expect(PrettyText.cook "y$+500$").not_to include("math")
expect(PrettyText.cook "($ +500 $)").to include("math")
2017-07-06 16:50:38 -04:00
end
it "can handle inline math" do
2017-07-06 16:50:38 -04:00
cooked = PrettyText.cook <<~MD
I like
$$
\{a,b\}\$<a>
$$
2017-07-18 14:40:05 -04:00
etc
2017-07-06 16:50:38 -04:00
MD
html = <<~HTML
<p>I like</p>
<div class="math">
{a,b}$&lt;a&gt;
</div>
2017-07-18 14:40:05 -04:00
<p>etc</p>
2017-07-06 16:50:38 -04:00
HTML
expect(cooked).to eq(html.strip)
end
end
end