parent
dee9ba5e5f
commit
35e0f51672
|
@ -229,7 +229,7 @@ fn add_toc(content: &str, cfg: &Config) -> Result<String> {
|
|||
log::trace!("content_after_toc={:?}", content_after_toc);
|
||||
// Multiline markers might have consumed trailing newlines,
|
||||
// we ensure there's always one before the content.
|
||||
let extra = if content_after_toc.as_bytes()[0] == b'\n' {
|
||||
let extra = if content_after_toc.is_empty() || content_after_toc.as_bytes()[0] == b'\n' {
|
||||
""
|
||||
} else {
|
||||
"\n"
|
||||
|
|
3
tests/empty_document.in.md
Normal file
3
tests/empty_document.in.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Chapter 1
|
||||
|
||||
<!-- toc -->
|
2
tests/empty_document.out.md
Normal file
2
tests/empty_document.out.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Chapter 1
|
||||
|
|
@ -157,3 +157,10 @@ fn backslash_escapes() {
|
|||
// Backslash-escaped elements should still be escaped.
|
||||
assert_toc!("backslash_escapes");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_document() {
|
||||
// Regression test #31
|
||||
// Empty documents should not fail
|
||||
assert_toc!("empty_document");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue