File: complex_conversion_test.exs

package info (click to toggle)
elixir-earmark-parser 1.4.44-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: makefile: 9
file content (104 lines) | stat: -rw-r--r-- 2,868 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
defmodule Test.Functional.Inline.Converter.ComplexConversionTest do
  use Support.InlineConverterCase

  describe "link_and_image:" do
    test "image inside link" do
      markdown = "[![moon](moon.jpg)](/uri)\n"

      expected = [
        "\n",
        {"a", [{"href", "/uri"}], [{"img", [{"src", "moon.jpg"}, {"alt", "moon"}], [], %{}}], %{}}
      ]

      assert convert(markdown) == expected
    end
  end

  describe "footnotes" do
    test "defined footnote" do
      markdown = " foo[^1] again"

      expected = [
        " again",
        {"a", [{"href", "#fn:1"}, {"id", "fnref:1"}, {"class", "footnote"}, {"title", "see footnote"}], ["1"], %{}},
        " foo"
      ]

      assert convert_with_footnotes(markdown, "1") == expected
    end

    test "undefined footnote" do
      markdown = " foo[^1] again"
      expected = [" foo[^1] again"]
      assert convert_with_footnotes(markdown, "2") == expected
    end
  end

  describe "pure links" do
    @link "http://www.google.com/search?q=business"

    test "a link inside parens" do
      markdown = "(#{@link})"

      expected = [
        ")",
        {"a", [{"href", "http://www.google.com/search?q=business"}], ["http://www.google.com/search?q=business"], %{}},
        "("
      ]

      assert convert(markdown) == expected
    end

    test " a link" do
      expected = [
        {"a", [{"href", "http://www.google.com/search?q=business"}], ["http://www.google.com/search?q=business"], %{}}
      ]

      assert convert(@link) == expected
    end
  end

  describe "reflink:" do
    test "image with title" do
      markdown = "[foo]: /url \"title\"\n\n![foo]\n"
      expected = ["[foo]: /url \"title\"\n\n![foo]\n"]
      assert convert(markdown) == expected
    end

    test "no image, url and title" do
      markdown = "[] [reference]"
      expected = [{"a", [{"href", "url1"}, {"title", "title1"}], [], %{}}]
      assert convert_with_reflink(markdown, "reference", "url1", "title1") == expected
    end

    test "no image, no title" do
      markdown = "[text] []"
      expected = ["[text] []"]
      assert convert_with_reflink(markdown, "reference", "url3", "title3") == expected
    end

    test "image" do
      markdown = "![text] [reference]\n[reference]: some_url 'a title'"

      expected = [
        ": some_url 'a title'",
        {"a", [{"href", "url2"}, {"title", "title2"}], ["reference"], %{}},
        "\n",
        {"img", [{"src", "url2"}, {"alt", "text"}, {"title", "title2"}], [], %{}}
      ]

      assert convert_with_reflink(markdown, "reference", "url2", "title2") == expected
    end
  end

  describe "wikilinks" do
    test "if enabled" do
      markdown = "[[page]]"
      expected = [a("page", [href: "page"], %{wikilink: true})]

      assert convert(markdown, wikilinks: true) == expected
    end
  end
end

# SPDX-License-Identifier: Apache-2.0