1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Tests for markdown rendering to manpage
16 module test_markdown_man
is test
19 import markdown_man_rendering
21 # Abstract test class that defines the test methods for Man rendering
22 abstract class TestMarkdownMan
25 # Man renderer used in tests
26 var man_renderer
= new ManRenderer
28 # Render the `md` string as Manpage format
29 fun md_to_man
(md
: String): String do
30 var node
= parse_md
(md
)
31 return man_renderer
.render
(node
)
35 class TestManRendering
39 fun test_headings
is test
do
40 var md
= """# title1\n## title2\n### title3\n#### title4\n##### title5\n###### title6\n"""
41 var man
= """.SH title1\n.SS title2\n.TP\ntitle3\n.TP\ntitle4\n.TP\ntitle5\n.TP\ntitle6\n"""
42 assert md_to_man
(md
) == man
45 fun test_bquotes
is test
do
46 var md
= """> line 1\n> line 2\n\n> line 3\n>line 4"""
47 var man
= """.RS\nline 1\nline 2\n.RE\n.RS\nline 3\nline 4\n.RE\n"""
48 assert md_to_man
(md
) == man
51 fun test_breaks
is test
do
54 assert md_to_man
(md
) == man
57 fun test_indented_code
is test
do
58 var md
= """\tline 1\n\tline 2\n"""
59 var man
= """.RS\n.nf\n\\f[C]\nline\\ 1\nline\\ 2\n\\f[]\n.fi\n.RE\n"""
60 assert md_to_man
(md
) == man
63 fun test_fenced_code
is test
do
64 var md
= """~~~\nline 1\nline 2\n~~~\n"""
65 var man
= """.RS\n.nf\n\\f[C]\nline\\ 1\nline\\ 2\n\\f[]\n.fi\n.RE\n"""
66 assert md_to_man
(md
) == man
69 fun test_escaped_code
is test
do
70 var md
= """\tline - 1\n\tline - 2\n"""
71 var man
= """.RS\n.nf\n\\f[C]\nline\\ \\-\\ 1\nline\\ \\-\\ 2\n\\f[]\n.fi\n.RE\n"""
72 assert md_to_man
(md
) == man
75 fun test_unordered_list
is test
do
76 var md
= """* line 1\n* line 2\n"""
77 var man
= """.RS\n.IP \\[bu] 3\nline 1\n.IP \\[bu] 3\nline 2\n.RE\n"""
78 assert md_to_man
(md
) == man
81 fun test_ordered_list
is test
do
82 var md
= """2) line 1\n3) line 2\n"""
83 var man
= """.RS\n.IP "2." 3\nline 1\n.IP "3." 3\nline 2\n.RE\n"""
84 assert md_to_man
(md
) == man
87 fun test_paragraph
is test
do
88 var md
= """line 1\nline 2\n\nline 3\nline 4\n"""
89 var man
= """\nline 1\nline 2\n\nline 3\nline 4\n"""
90 assert md_to_man
(md
) == man
93 fun test_escaped_text
is test
do
94 var md
= """foo - bar\n"""
95 var man
= """\nfoo \\- bar\n"""
96 assert md_to_man
(md
) == man
99 fun test_inline_code
is test
do
100 var md
= """`foo - bar`\n"""
101 var man
= """\n\\f[C]foo\\ \\-\\ bar\\f[]\n"""
102 assert md_to_man
(md
) == man
105 fun test_emphasis
is test
do
106 var md
= """*foo*\n"""
107 var man
= """\n\\f[I]foo\\f[]\n"""
108 assert md_to_man
(md
) == man
111 fun test_strong_emphasis
is test
do
112 var md
= """**foo**\n"""
113 var man
= """\n\\f[B]foo\\f[]\n"""
114 assert md_to_man
(md
) == man
117 fun test_link
is test
do
118 var md
= """[foo](url "title")\n"""
119 var man
= """\nfoo (url title)\n"""
120 assert md_to_man
(md
) == man
123 fun test_image
is test
do
124 var md
= """![foo](url "title")\n"""
125 var man
= """\nfoo (url title)\n"""
126 assert md_to_man
(md
) == man
129 fun test_full_document
is test
do
134 nitdoc - generates HTML pages of API documentation from Nit source files.
138 nitdoc [*options*]... FILE...
142 `nitdoc` takes one or more modules and generate HTML pages of API documentation for these modules and their imported modules.
144 The documentation is extracted from the comments found above the definition of modules, classes, and properties.
146 Internally, `nitdoc` relies on the presence of the `dot` command from the [graphviz] project.
147 If the dot program is not present or not found, no image of hierarchies are generated.
148 See option `--no-dot`.
150 The documentation of the Nit [standard library] is generated with this tool.
152 [graphviz]: http://www.graphviz.org
153 [standard library]: http://nitlanguage.org/doc/stdlib
155 # DOCUMENTATION FORMAT
157 The format of the documentation is a dialect of [markdown] that allows GitHub fences (`~~~`).
159 Code blocks are interpreted as snippets of Nit programs and intended to be used as examples of code.
160 When these code snippets are valid, executable and contain at least and `assert` clause, they could be automatically executed and verified.
161 See `nitunit(1)` for details.
163 [markdown]: http://daringfireball.net/projects/markdown
170 Where the HTML files are generated.
172 By default, the directory is named `doc`.
175 Format to link source code.
177 The format string is used to generated links to some parts of the source-code.
178 Use `%f` for filename, `%l` for first line, and `%L` for last line.
180 For instance, the [standard library] use the following value to link to files in GitHub:
182 "https://github.com/nitlang/nit/blob/$(git rev-parse HEAD)/%f#L%l-%L"
184 Here, the `git rev-parse HEAD` is used to link to the current snapshot revision of the file.
186 ### `--no-attributes`
187 Ignore the attributes.
189 Note: In Nit, attributes are private. Therefore, this option is only useful
190 when combined with `--private`.
193 Do not generate graphs with graphviz.
196 Also generate private API.
201 Directory containing tools assets.
203 By default `$NIT_DIR/share/nitdoc/` is used.
206 Use shareurl instead of copy shared files.
208 By default, assets from the sharedir a copied into the output directory and referred with a relative path in the generated files.
209 With this option, the assets are not copied and the given URL of path is used in the generated files to locate assets.
212 Custom title for homepage.
214 ### `--custom-footer-text`
217 ### `--custom-overview-text`
218 Custom intro text for homepage.
221 Custom link to external site.
225 ### `--github-upstream`
226 Git branch where edited commits will be pulled into (ex: user:repo:branch).
228 ### `--github-base-sha1`
229 Git sha1 of base commit used to create pull request.
231 ### `--github-gitdir`
232 Git working directory used to resolve path name (ex: /home/me/myproject/).
234 ### `--piwik-tracker`
235 Piwik tracker URL (ex: `nitlanguage.org/piwik/`).
237 ### `--piwik-site-id`
243 Print test data (metrics and structure).
246 Do not render HTML files.
250 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>
256 nitdoc \\- generates HTML pages of API documentation from Nit source files.
259 nitdoc [\\f[I]options\\f[]]... FILE...
262 \\f[C]nitdoc\\f[] takes one or more modules and generate HTML pages of API documentation for these modules and their imported modules.
264 The documentation is extracted from the comments found above the definition of modules, classes, and properties.
266 Internally, \\f[C]nitdoc\\f[] relies on the presence of the \\f[C]dot\\f[] command from the graphviz (http://www.graphviz.org) project.
267 If the dot program is not present or not found, no image of hierarchies are generated.
268 See option \\f[C]\\-\\-no\\-dot\\f[].
270 The documentation of the Nit standard library (http://nitlanguage.org/doc/stdlib) is generated with this tool.
271 .SH DOCUMENTATION FORMAT
273 The format of the documentation is a dialect of markdown (http://daringfireball.net/projects/markdown) that allows GitHub fences (\\f[C]~~~\\f[]).
275 Code blocks are interpreted as snippets of Nit programs and intended to be used as examples of code.
276 When these code snippets are valid, executable and contain at least and \\f[C]assert\\f[] clause, they could be automatically executed and verified.
277 See \\f[C]nitunit(1)\\f[] for details.
280 \\f[C]\\-d\\f[], \\f[C]\\-\\-dir\\f[]
284 Where the HTML files are generated.
286 By default, the directory is named \\f[C]doc\\f[].
288 \\f[C]\\-\\-source\\f[]
290 Format to link source code.
292 The format string is used to generated links to some parts of the source\\-code.
293 Use \\f[C]%f\\f[] for filename, \\f[C]%l\\f[] for first line, and \\f[C]%L\\f[] for last line.
295 For instance, the standard library (http://nitlanguage.org/doc/stdlib) use the following value to link to files in GitHub:
299 "https://github.com/nitlang/nit/blob/$(git\\ rev\\-parse\\ HEAD)/%f#L%l\\-%L"
304 Here, the \\f[C]git\\ rev\\-parse\\ HEAD\\f[] is used to link to the current snapshot revision of the file.
306 \\f[C]\\-\\-no\\-attributes\\f[]
308 Ignore the attributes.
310 Note: In Nit, attributes are private. Therefore, this option is only useful
311 when combined with \\f[C]\\-\\-private\\f[].
313 \\f[C]\\-\\-no\\-dot\\f[]
315 Do not generate graphs with graphviz.
317 \\f[C]\\-\\-private\\f[]
319 Also generate private API.
322 \\f[C]\\-\\-share\\-dir\\f[]
324 Directory containing tools assets.
326 By default \\f[C]$NIT_DIR/share/nitdoc/\\f[] is used.
328 \\f[C]\\-\\-shareurl\\f[]
330 Use shareurl instead of copy shared files.
332 By default, assets from the sharedir a copied into the output directory and referred with a relative path in the generated files.
333 With this option, the assets are not copied and the given URL of path is used in the generated files to locate assets.
335 \\f[C]\\-\\-custom\\-title\\f[]
337 Custom title for homepage.
339 \\f[C]\\-\\-custom\\-footer\\-text\\f[]
343 \\f[C]\\-\\-custom\\-overview\\-text\\f[]
345 Custom intro text for homepage.
347 \\f[C]\\-\\-custom\\-brand\\f[]
349 Custom link to external site.
352 \\f[C]\\-\\-github\\-upstream\\f[]
354 Git branch where edited commits will be pulled into (ex: user:repo:branch).
356 \\f[C]\\-\\-github\\-base\\-sha1\\f[]
358 Git sha1 of base commit used to create pull request.
360 \\f[C]\\-\\-github\\-gitdir\\f[]
362 Git working directory used to resolve path name (ex: /home/me/myproject/).
364 \\f[C]\\-\\-piwik\\-tracker\\f[]
366 Piwik tracker URL (ex: \\f[C]nitlanguage.org/piwik/\\f[]).
368 \\f[C]\\-\\-piwik\\-site\\-id\\f[]
373 \\f[C]\\-\\-test\\f[]
375 Print test data (metrics and structure).
377 \\f[C]\\-\\-no\\-render\\f[]
379 Do not render HTML files.
382 The Nit language documentation and the source code of its tools and libraries may be downloaded from http://nitlanguage.org (http://nitlanguage.org)
384 assert md_to_man
(md
) == man