Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub static LAZY_BOOK: use_mdbook::Lazy<use_mdbook::mdbook_shared::MdBook<BookRou
sections: vec![
::use_mdbook::mdbook_shared::Section {
title: "Roadmap & Feature-set".to_string(),
id: "roadmap-&-feature-set".to_string(),
id: "roadmap--feature-set".to_string(),
level: 1usize,
},
::use_mdbook::mdbook_shared::Section {
Expand Down Expand Up @@ -123,7 +123,7 @@ pub static LAZY_BOOK: use_mdbook::Lazy<use_mdbook::mdbook_shared::MdBook<BookRou
},
::use_mdbook::mdbook_shared::Section {
title: "Bundling (CLI)".to_string(),
id: "bundling-(cli)".to_string(),
id: "bundling-cli".to_string(),
level: 3usize,
},
::use_mdbook::mdbook_shared::Section {
Expand Down
23 changes: 17 additions & 6 deletions packages/include_mdbook/packages/mdbook-shared/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,37 @@ impl MdBook<PathBuf> {

let mut sections = Vec::new();

let mut title = String::new();

parser.for_each(|event| match event {
Event::Start(Tag::Heading(level, ..)) => {
title.clear();
last_heading = Some(level);
}
Event::Text(text) => {
Event::Text(text) | Event::Code(text) => {
title.push_str(&text);
}
Event::End(Tag::Heading(_, _, _)) => {
if let Some(current_level) = &mut last_heading {
let anchor = text
let anchor = title
.clone()
.into_string()
.trim()
.to_lowercase()
.chars()
.filter(|c| {
c.is_ascii_alphanumeric() || *c == ' ' || *c == '-' || *c == '_'
})
.collect::<String>()
.replace('_', "-")
.replace(' ', "-");
sections.push(Section {
level: *current_level as usize,
title: text.to_string(),
title: title.clone(),
id: anchor,
});

last_heading = None;
}

last_heading = None;
}
_ => {}
});
Expand Down