1import nixos_render_docs as nrd
2
3from sample_md import sample1
4
5from typing import Mapping
6
7
8class Converter(nrd.md.Converter[nrd.commonmark.CommonMarkRenderer]):
9 def __init__(self, manpage_urls: Mapping[str, str]):
10 super().__init__()
11 self._renderer = nrd.commonmark.CommonMarkRenderer(manpage_urls)
12
13# NOTE: in these tests we represent trailing spaces by ` ` and replace them with real space later,
14# since a number of editors will strip trailing whitespace on save and that would break the tests.
15
16def test_indented_fence() -> None:
17 c = Converter({})
18 s = """\
19> - ```foo
20> thing
21>
22> rest
23> ```\
24""".replace(' ', ' ')
25 assert c._render(s) == s
26
27def test_full() -> None:
28 c = Converter({ 'man(1)': 'http://example.org' })
29 assert c._render(sample1) == """\
30**Warning:** foo
31
32**Note:** nested
33
34[
35multiline
36](link)
37
38[` man(1) `](http://example.org) reference
39
40some nested anchors
41
42*emph* **strong** *nesting emph **and strong** and ` code `*
43
44 - wide bullet
45
46 - list
47
48 1. wide ordered
49
50 2. list
51
52 - narrow bullet
53 - list
54
55 1. narrow ordered
56 2. list
57
58> quotes
59>
60> > with *nesting*
61> >
62> > ```
63> > nested code block
64> > ```
65>
66> - and lists
67> - ```
68> containing code
69> ```
70>
71> and more quote
72
73 100. list starting at 100
74 101. goes on
75
76 - *deflist*
77
78 > with a quote
79 > and stuff
80
81 ```
82 code block
83 ```
84
85 ```
86 fenced block
87 ```
88
89 text
90
91 - *more stuff in same deflist*
92
93 foo""".replace(' ', ' ')
94
95def test_images() -> None:
96 c = Converter({})
97 assert c._render("") == (
98 ""
99 )