Skip to content

Commit 1e6157b

Browse files
jonathanpallantlistochkin
authored andcommitted
Ignore empty headings.
1 parent 39af1b8 commit 1e6157b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ pub fn run(
9999
IndexEntry::SubHeading(_heading) => {
100100
// Ignore
101101
}
102+
IndexEntry::Chapter { title, path } if path.is_empty() => {
103+
log::info!("Processing placeholder: {:?}", title);
104+
}
102105
IndexEntry::Chapter { title, path } => {
103106
log::info!("Processing {}: {:?}", path, title);
104107
let in_path = {
@@ -265,6 +268,13 @@ pub fn generate_index(
265268
let mut heading_is_open = false;
266269
for entry in chapters {
267270
match entry {
271+
IndexEntry::Chapter { title, path } if path.is_empty() => {
272+
if !heading_is_open {
273+
generated_html.push_str("<ul>\n");
274+
heading_is_open = true;
275+
}
276+
generated_html.push_str(&format!("<li>{}</li>\n", title));
277+
}
268278
IndexEntry::Chapter { title, path } => {
269279
if !heading_is_open {
270280
generated_html.push_str("<ul>\n");
@@ -327,6 +337,10 @@ mod test {
327337
title: "Link Title 2".to_owned(),
328338
path: "./test2.md".to_owned(),
329339
},
340+
IndexEntry::Chapter {
341+
title: "Link Title 3".to_owned(),
342+
path: String::new(),
343+
},
330344
];
331345
let title = "My Title";
332346
let template = "<title>$TITLE</title>\n$INDEX";
@@ -344,6 +358,7 @@ mod test {
344358
<h2>SubHeading 2</h2>\n\
345359
<ul>\n\
346360
<li><a href=\"./test2.html\">Link Title 2</a></li>\n\
361+
<li>Link Title 3</li>\n\
347362
</ul>\n"
348363
);
349364
}
@@ -370,7 +385,7 @@ mod test {
370385
## Subheading 2.1\n\
371386
\n\
372387
- [Link 5](./link5.md)\n\
373-
- [Link 6](./link6.md)\n\
388+
- [Link 6]()\n\
374389
";
375390
let index_entries = load_book(summary_src).unwrap();
376391
assert_eq!(
@@ -403,7 +418,7 @@ mod test {
403418
},
404419
IndexEntry::Chapter {
405420
title: "Link 6".to_string(),
406-
path: "./link6.md".to_string()
421+
path: String::new(),
407422
},
408423
]
409424
);

0 commit comments

Comments
 (0)