summaryrefslogtreecommitdiffstats
path: root/tests/test_port/test_references.py
blob: 32e389dee3cc2664324a359ac429a2b93bedf2f0 (plain)
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
from markdown_it import MarkdownIt


def test_ref_definitions():

    md = MarkdownIt()
    src = "[a]: abc\n\n[b]: xyz\n\n[b]: ijk"
    env = {}
    tokens = md.parse(src, env)
    assert tokens == []
    assert env == {
        "references": {
            "A": {"title": "", "href": "abc", "map": [0, 1]},
            "B": {"title": "", "href": "xyz", "map": [2, 3]},
        },
        "duplicate_refs": [{"href": "ijk", "label": "B", "map": [4, 5], "title": ""}],
    }


def test_use_existing_env(data_regression):
    md = MarkdownIt()
    src = "[a]\n\n[c]: ijk"
    env = {
        "references": {
            "A": {"title": "", "href": "abc", "map": [0, 1]},
            "B": {"title": "", "href": "xyz", "map": [2, 3]},
        }
    }
    tokens = md.parse(src, env)
    data_regression.check([token.as_dict() for token in tokens])
    assert env == {
        "references": {
            "A": {"title": "", "href": "abc", "map": [0, 1]},
            "B": {"title": "", "href": "xyz", "map": [2, 3]},
            "C": {"title": "", "href": "ijk", "map": [2, 3]},
        }
    }


def test_store_labels(data_regression):
    md = MarkdownIt()
    md.options["store_labels"] = True
    src = "[a]\n\n![a]\n\n[a]: ijk"
    tokens = md.parse(src)
    data_regression.check([token.as_dict() for token in tokens])


def test_inline_definitions(data_regression):
    md = MarkdownIt()
    md.options["inline_definitions"] = True
    src = '[a]: url "title"\n- [a]: url "title"'
    tokens = md.parse(src)
    data_regression.check([token.as_dict() for token in tokens])