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 # Test for markdown headings id generation
16 module test_markdown_headings_id
is test
20 class TestMarkdownHeadingsId
21 super TestMarkdownHtml
24 redef var html_renderer
= new HtmlRenderer(true)
26 fun test_multiple_ids
is test
do
27 var md
= """# foo\n## foo\n### foo\n#### foo\n##### foo\n###### foo\n"""
28 var html
= """<h1 id="foo">foo</h1>\n<h2 id="foo_1">foo</h2>\n<h3 id="foo_2">foo</h3>\n<h4 id="foo_3">foo</h4>\n<h5 id="foo_4">foo</h5>\n<h6 id="foo_5">foo</h6>\n"""
29 assert md_to_html
(md
) == html
32 fun test_escape_ids
is test
do
33 var md
= """# foo *bar* \\*baz\\*\n"""
34 var html
= """<h1 id="foo_bar_baz">foo <em>bar</em> *baz*</h1>\n"""
35 assert md_to_html
(md
) == html
38 fun test_escape_ids2
is test
do
39 var md
= """# foo#\n"""
40 var html
= """<h1 id="foo">foo#</h1>\n"""
41 assert md_to_html
(md
) == html
44 fun test_avoid_spaces
is test
do
45 var md
= """# foo \n"""
46 var html
= """<h1 id="foo">foo</h1>\n"""
47 assert md_to_html
(md
) == html
50 fun test_remove_atx_trailing
is test
do
51 var md
= """## foo ##\n ### bar ###\n"""
52 var html
= """<h2 id="foo">foo</h2>\n<h3 id="bar">bar</h3>\n"""
53 assert md_to_html
(md
) == html
56 fun test_avoid_escaped_chars
is test
do
57 var md
= """### foo \\###\n## foo #\\##\n# foo \\#\n"""
58 var html
= """<h3 id="foo_">foo ###</h3>\n<h2 id="foo__1">foo ###</h2>\n<h1 id="foo__2">foo #</h1>\n"""
59 assert md_to_html
(md
) == html