diff options
| author | Konsta Hölttä | 2020-10-25 17:35:52 +0200 |
|---|---|---|
| committer | GitHub | 2020-10-25 16:35:52 +0100 |
| commit | b0c55246570b9c04e732eee43e6c02d6f3a043a4 (patch) | |
| tree | c48025d287d31506b356f5904094881245eaf6a2 | |
| parent | bc3325285dacd3731893295e6ec2e8c502929c5b (diff) | |
| download | rust-rst-b0c55246570b9c04e732eee43e6c02d6f3a043a4.tar.bz2 | |
Decrement renderer level after section recursion (#16)
The html renderer section level used for title numbering is incremented
when entering a new section so that subsections get correct heading
elements. Match the increment with a decrement after having rendered the
section contents, so that multiple consecutive sections would stay
consistent.
Add a test to verify this behaviour.
| -rw-r--r-- | renderer/src/html.rs | 1 | ||||
| -rw-r--r-- | renderer/src/html/tests.rs | 49 |
2 files changed, 50 insertions, 0 deletions
diff --git a/renderer/src/html.rs b/renderer/src/html.rs index 0092315..bb7c42e 100644 --- a/renderer/src/html.rs +++ b/renderer/src/html.rs @@ -152,6 +152,7 @@ impl HTMLRender for e::Section { writeln!(renderer.stream)?; } write!(renderer.stream, "</section>")?; + renderer.level -= 1; Ok(()) } } diff --git a/renderer/src/html/tests.rs b/renderer/src/html/tests.rs index b380847..5d63fcb 100644 --- a/renderer/src/html/tests.rs +++ b/renderer/src/html/tests.rs @@ -203,6 +203,55 @@ And even more stuff } #[test] +fn many_sections() { + check_renders_to("\ ++++++++++ +heading 1 ++++++++++ + +heading 2 +========= + +First stuff + +heading 2a +---------- + +First detail + +heading 3 +========= + +Second stuff + +heading 3a +---------- + +Second detail +", "\ +<section id=\"heading-1\"> +<h1>heading 1</h1> +<section id=\"heading-2\"> +<h2>heading 2</h2> +<p>First stuff</p> +<section id=\"heading-2a\"> +<h3>heading 2a</h3> +<p>First detail</p> +</section> +</section> +<section id=\"heading-3\"> +<h2>heading 3</h2> +<p>Second stuff</p> +<section id=\"heading-3a\"> +<h3>heading 3a</h3> +<p>Second detail</p> +</section> +</section> +</section>\ +"); +} + +#[test] fn bullet_list() { check_renders_to("\ * bullet |
