From e36e222f234e8316392a887c73382645bc48e46f Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 31 May 2024 18:45:05 +0200 Subject: [PATCH] generate id for headers --- src/convert.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/convert.rs b/src/convert.rs index 93df3e2..0184870 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -37,8 +37,17 @@ pub fn convert_document(markdown: &str) -> String { state = S::None; html += "

\n"; } + let id: String = header + .to_lowercase() + .chars() + .filter_map(|c| match c { + ' ' => Some('-'), + '-' | '_' => Some(c), + _ => c.is_alphanumeric().then_some(c), + }) + .collect(); let header = &convert_line(header); - html += &format!("{header}\n"); + html += &format!("{header}\n"); continue; } }