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.manpage.ManpageRenderer]):
9 def __init__(self, manpage_urls: Mapping[str, str], options_by_id: dict[str, str] = {}):
10 super().__init__()
11 self._renderer = nrd.manpage.ManpageRenderer(manpage_urls, options_by_id)
12
13def test_inline_code() -> None:
14 c = Converter({})
15 assert c._render("1 `x a x` 2") == "1 \\fR\\(oqx a x\\(cq\\fP 2"
16
17def test_fonts() -> None:
18 c = Converter({})
19 assert c._render("*a **b** c*") == "\\fIa \\fBb\\fI c\\fR"
20 assert c._render("*a [1 `2`](3) c*") == "\\fIa \\fB1 \\fR\\(oq2\\(cq\\fP\\fI c\\fR"
21
22def test_expand_link_targets() -> None:
23 c = Converter({}, { '#foo1': "bar", "#foo2": "bar" })
24 assert (c._render("[a](#foo1) [](#foo2) [b](#bar1) [](#bar2)") ==
25 "\\fBa\\fR \\fBbar\\fR \\fBb\\fR \\fB\\fR")
26
27def test_collect_links() -> None:
28 c = Converter({}, { '#foo': "bar" })
29 c._renderer.link_footnotes = []
30 assert c._render("[a](link1) [b](link2)") == "\\fBa\\fR[1]\\fR \\fBb\\fR[2]\\fR"
31 assert c._renderer.link_footnotes == ['link1', 'link2']
32
33def test_dedup_links() -> None:
34 c = Converter({}, { '#foo': "bar" })
35 c._renderer.link_footnotes = []
36 assert c._render("[a](link) [b](link)") == "\\fBa\\fR[1]\\fR \\fBb\\fR[1]\\fR"
37 assert c._renderer.link_footnotes == ['link']
38
39def test_full() -> None:
40 c = Converter({ 'man(1)': 'http://example.org' })
41 assert c._render(sample1) == """\
42.sp
43.RS 4
44\\fBWarning\\fP
45.br
46foo
47.sp
48.RS 4
49\\fBNote\\fP
50.br
51nested
52.RE
53.RE
54.sp
55\\fBmultiline\\fR
56.sp
57\\fBman\\fP\\fR(1)\\fP reference
58.sp
59some nested anchors
60.sp
61\\fIemph\\fR \\fBstrong\\fR \\fInesting emph \\fBand strong\\fI and \\fR\\(oqcode\\(cq\\fP\\fR
62.sp
63.RS 4
64\\h'-2'\\fB\\[u2022]\\fP\\h'1'\\c
65wide bullet
66.RE
67.sp
68.RS 4
69\\h'-2'\\fB\\[u2022]\\fP\\h'1'\\c
70list
71.RE
72.sp
73.RS 4
74\\h'-3'\\fB1\\&.\\fP\\h'1'\\c
75wide ordered
76.RE
77.sp
78.RS 4
79\\h'-3'\\fB2\\&.\\fP\\h'1'\\c
80list
81.RE
82.sp
83.RS 4
84\\h'-2'\\fB\\[u2022]\\fP\\h'1'\\c
85narrow bullet
86.RE
87.RS 4
88\\h'-2'\\fB\\[u2022]\\fP\\h'1'\\c
89list
90.RE
91.sp
92.RS 4
93\\h'-3'\\fB1\\&.\\fP\\h'1'\\c
94narrow ordered
95.RE
96.RS 4
97\\h'-3'\\fB2\\&.\\fP\\h'1'\\c
98list
99.RE
100.sp
101.RS 4
102\\h'-3'\\fI\\(lq\\(rq\\fP\\h'1'\\c
103quotes
104.sp
105.RS 4
106\\h'-3'\\fI\\(lq\\(rq\\fP\\h'1'\\c
107with \\fInesting\\fR
108.sp
109.RS 4
110.nf
111nested code block
112.fi
113.RE
114.RE
115.sp
116.RS 4
117\\h'-2'\\fB\\[u2022]\\fP\\h'1'\\c
118and lists
119.RE
120.RS 4
121\\h'-2'\\fB\\[u2022]\\fP\\h'1'\\c
122.sp
123.RS 4
124.nf
125containing code
126.fi
127.RE
128.RE
129.sp
130and more quote
131.RE
132.sp
133.RS 6
134\\h'-5'\\fB100\\&.\\fP\\h'1'\\c
135list starting at 100
136.RE
137.RS 6
138\\h'-5'\\fB101\\&.\\fP\\h'1'\\c
139goes on
140.RE
141.RS 4
142.PP
143deflist
144.RS 4
145.RS 4
146\\h'-3'\\fI\\(lq\\(rq\\fP\\h'1'\\c
147with a quote and stuff
148.RE
149.sp
150.RS 4
151.nf
152code block
153.fi
154.RE
155.sp
156.RS 4
157.nf
158fenced block
159.fi
160.RE
161.sp
162text
163.RE
164.PP
165more stuff in same deflist
166.RS 4
167foo
168.RE
169.RE"""