1
0
mirror of https://github.com/lise-henry/crowbook synced 2024-11-18 00:13:55 +01:00

fixed bug in toc.rs

This commit is contained in:
Elisabeth Henry 2016-02-24 19:48:55 +01:00
parent 0a19bb7929
commit 8d763992ff
2 changed files with 16 additions and 5 deletions

@ -53,6 +53,10 @@ impl Toc {
*level = elem.level;
}
} else if elem.level < *level {
for i in (elem.level..*level).rev() {
content.push_str(&format!("{}</ul>\n",
iter::repeat(' ').take(i as usize).collect::<String>()));
}
*level = elem.level;
}
let spaces:String = iter::repeat(' ').take(elem.level as usize).collect();
@ -63,9 +67,9 @@ impl Toc {
content.push_str(&format!("{}</ul>\n",
iter::repeat(' ').take(i as usize).collect::<String>()));
}
*level = elem.level;
content.push_str(&format!("{}</li>\n", spaces));
}
content
}

@ -7,20 +7,27 @@ use test_helper::test_eq;
#[test]
fn toc_simple() {
let mut toc = Toc::new();
toc.add(1, String::new(), "0".to_owned());
toc.add(3, String::new(), "0.0.1".to_owned());
toc.add(1, String::new(), "1".to_owned());
toc.add(3, String::new(), "1.0.1".to_owned());
toc.add(2, String::new(), "1.1".to_owned());
toc.add(1, String::new(), "2".to_owned());
let actual = toc.render();
let expected = "<ul>
<li>0
</li>
<ul>
<ul>
<li>0.0.1
</li>
</ul>
</ul>
<li>1
<ul>
<ul>
<li>1.0.1
</li>
</ul>
<li>1.1
</li>
</ul>
</li>
<li>2