logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

earmark_renderer_test.exs (3083B)


  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. test "Paragraph" do
  7. code = ~s[Hello\n\nWorld!]
  8. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  9. assert result == "<p>Hello</p><p>World!</p>"
  10. end
  11. test "raw HTML" do
  12. code = ~s[<a href="http://example.org/">OwO</a><!-- what's this?-->]
  13. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  14. assert result == "<p>#{code}</p>"
  15. end
  16. test "rulers" do
  17. code = ~s[before\n\n-----\n\nafter]
  18. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  19. assert result == "<p>before</p><hr /><p>after</p>"
  20. end
  21. test "headings" do
  22. code = ~s[# h1\n## h2\n### h3\n]
  23. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  24. assert result == ~s[<h1>h1</h1><h2>h2</h2><h3>h3</h3>]
  25. end
  26. test "blockquote" do
  27. code = ~s[> whoms't are you quoting?]
  28. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  29. assert result == "<blockquote><p>whoms’t are you quoting?</p></blockquote>"
  30. end
  31. test "code" do
  32. code = ~s[`mix`]
  33. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  34. assert result == ~s[<p><code class="inline">mix</code></p>]
  35. code = ~s[``mix``]
  36. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  37. assert result == ~s[<p><code class="inline">mix</code></p>]
  38. code = ~s[```\nputs "Hello World"\n```]
  39. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  40. assert result == ~s[<pre><code class="">puts &quot;Hello World&quot;</code></pre>]
  41. end
  42. test "lists" do
  43. code = ~s[- one\n- two\n- three\n- four]
  44. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  45. assert result == "<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>"
  46. code = ~s[1. one\n2. two\n3. three\n4. four\n]
  47. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  48. assert result == "<ol><li>one</li><li>two</li><li>three</li><li>four</li></ol>"
  49. end
  50. test "delegated renderers" do
  51. code = ~s[a<br/>b]
  52. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  53. assert result == "<p>#{code}</p>"
  54. code = ~s[*aaaa~*]
  55. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  56. assert result == ~s[<p><em>aaaa~</em></p>]
  57. code = ~s[**aaaa~**]
  58. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  59. assert result == ~s[<p><strong>aaaa~</strong></p>]
  60. # strikethrought
  61. code = ~s[<del>aaaa~</del>]
  62. result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
  63. assert result == ~s[<p><del>aaaa~</del></p>]
  64. end
  65. end