File: test_markdown.py

package info (click to toggle)
ford 7.0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,004 kB
  • sloc: python: 12,017; f90: 419; javascript: 51; fortran: 45; makefile: 23
file content (57 lines) | stat: -rw-r--r-- 1,515 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
from ford._markdown import MetaMarkdown

from textwrap import dedent


def test_sub_alias():
    result = MetaMarkdown(aliases={"a": "b"}).convert("|a|")
    assert result == "<p>b</p>"

    result = MetaMarkdown(aliases={"a": "b"}).convert("|undefined|")
    assert result == "<p>|undefined|</p>"


def test_sub_alias_escape():
    def_alias = {"a": "b"}

    result = MetaMarkdown(aliases=def_alias).convert("\|a|")
    assert result == "<p>|a|</p>"

    result = MetaMarkdown(aliases=def_alias).convert("*|a|")
    assert result == "<p>*b</p>"

    result = MetaMarkdown(aliases=def_alias).convert("\|undefined|")
    assert result == "<p>|undefined|</p>"


def test_sub_alias_with_equals():
    result = MetaMarkdown(aliases={"a": "b=c"}).convert("|a|")

    assert result == "<p>b=c</p>"


def test_sub_alias_in_table():
    text = dedent("""
        |Table Col 1| Table Col 2 |
        |-----------| ----------- |
        |normal| entry |
        | [link](|page|/subpage2.html) | |other| |
        """)

    result = MetaMarkdown(
        aliases={"page": "/home/page", "other": "some alias"}
    ).convert(text)

    assert "[link]" not in result
    assert 'href="/home/page/subpage2.html"' in result
    assert "some alias" in result


def test_fix_relative_paths(tmp_path):
    base_path = tmp_path / "output"
    md = MetaMarkdown(base_url=tmp_path / "output")

    text = f"[link to thing]({base_path / 'thing'})"
    result = md.convert(text, path=base_path / "other")

    assert "../thing" in result