Merge branch 'stable' into stable-sync/2.1.1
[akkoma] / test / earmark_renderer_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4 defmodule Pleroma.EarmarkRendererTest do
5 use ExUnit.Case
6
7 test "Paragraph" do
8 code = ~s[Hello\n\nWorld!]
9 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
10 assert result == "<p>Hello</p><p>World!</p>"
11 end
12
13 test "raw HTML" do
14 code = ~s[<a href="http://example.org/">OwO</a><!-- what's this?-->]
15 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
16 assert result == "<p>#{code}</p>"
17 end
18
19 test "rulers" do
20 code = ~s[before\n\n-----\n\nafter]
21 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
22 assert result == "<p>before</p><hr /><p>after</p>"
23 end
24
25 test "headings" do
26 code = ~s[# h1\n## h2\n### h3\n]
27 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
28 assert result == ~s[<h1>h1</h1><h2>h2</h2><h3>h3</h3>]
29 end
30
31 test "blockquote" do
32 code = ~s[> whoms't are you quoting?]
33 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
34 assert result == "<blockquote><p>whoms’t are you quoting?</p></blockquote>"
35 end
36
37 test "code" do
38 code = ~s[`mix`]
39 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
40 assert result == ~s[<p><code class="inline">mix</code></p>]
41
42 code = ~s[``mix``]
43 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
44 assert result == ~s[<p><code class="inline">mix</code></p>]
45
46 code = ~s[```\nputs "Hello World"\n```]
47 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
48 assert result == ~s[<pre><code class="">puts &quot;Hello World&quot;</code></pre>]
49 end
50
51 test "lists" do
52 code = ~s[- one\n- two\n- three\n- four]
53 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
54 assert result == "<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>"
55
56 code = ~s[1. one\n2. two\n3. three\n4. four\n]
57 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
58 assert result == "<ol><li>one</li><li>two</li><li>three</li><li>four</li></ol>"
59 end
60
61 test "delegated renderers" do
62 code = ~s[a<br/>b]
63 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
64 assert result == "<p>#{code}</p>"
65
66 code = ~s[*aaaa~*]
67 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
68 assert result == ~s[<p><em>aaaa~</em></p>]
69
70 code = ~s[**aaaa~**]
71 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
72 assert result == ~s[<p><strong>aaaa~</strong></p>]
73
74 # strikethrought
75 code = ~s[<del>aaaa~</del>]
76 result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
77 assert result == ~s[<p><del>aaaa~</del></p>]
78 end
79 end