diff --git a/src/book/bookitem.rs b/src/book/bookitem.rs index a2ec2cb0..c33804aa 100644 --- a/src/book/bookitem.rs +++ b/src/book/bookitem.rs @@ -2,10 +2,11 @@ use serde::{Serialize, Serializer}; use serde::ser::SerializeStruct; use std::path::PathBuf; +type Section = Vec; #[derive(Debug, Clone)] pub enum BookItem { - Chapter(String, Chapter), // String = section + Chapter(Section, Chapter), Affix(Chapter), Spacer, } diff --git a/src/parse/summary.rs b/src/parse/summary.rs index 1193b6f5..b4434ea5 100644 --- a/src/parse/summary.rs +++ b/src/parse/summary.rs @@ -110,9 +110,7 @@ fn parse_level(summary: &mut Vec<&str>, // Increment section let len = section.len() - 1; section[len] += 1; - let s = section.iter() - .fold("".to_owned(), |s, i| s + &i.to_string() + "."); - BookItem::Chapter(s, ch) + BookItem::Chapter(section.clone(), ch) } _ => parsed_item, } @@ -181,7 +179,7 @@ fn parse_line(l: &str) -> Option { debug!("[*]: Line is list element"); if let Some((name, path)) = read_link(line) { - return Some(BookItem::Chapter("0".to_owned(), Chapter::new(name, path))); + return Some(BookItem::Chapter(vec![0], Chapter::new(name, path))); } else { return None; } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 14e45c23..2dbe3231 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -407,7 +407,9 @@ fn make_data(book: &MDBook, config: &Config) -> Result { - chapter.insert("section".to_owned(), json!(s)); + let section = s.iter() + .fold("".to_owned(), |s, i| s + &i.to_string() + "."); + chapter.insert("section".to_owned(), json!(section)); chapter.insert("name".to_owned(), json!(ch.name)); let path = ch.path.to_str().ok_or_else(|| { io::Error::new(io::ErrorKind::Other,