diff --git a/src/utils/markdown.rs b/src/utils/markdown.rs index 7a7ae14..2a7d01f 100644 --- a/src/utils/markdown.rs +++ b/src/utils/markdown.rs @@ -11,6 +11,7 @@ use std::path::Path; use std::sync::Arc; use crate::utils::metadata::MType; +use crate::utils::misc::remove_first_letter; use super::metadata::{get, MFile, Metadata}; @@ -213,13 +214,8 @@ fn fix_headers_ids(html: &str, path: Option<&FilePath>) -> String { element_content_handlers: vec![element!( "a:not(.footnote-ref):not(.footnote-backref)[href^='#']", |el| { - /// Remove the first character of a string - fn remove_anchor(s: &str) -> &str { - s.chars().next().map(|c| &s[c.len_utf8()..]).unwrap() - } - let id = el.get_attribute("id").unwrap_or( - path_to_hid(path) + remove_anchor(&el.get_attribute("href").unwrap()), + path_to_hid(path) + remove_first_letter(&el.get_attribute("href").unwrap()), ); el.set_attribute("href", &format!("#{id}")).unwrap(); Ok(()) diff --git a/src/utils/misc.rs b/src/utils/misc.rs index 34dfe8f..c9678be 100644 --- a/src/utils/misc.rs +++ b/src/utils/misc.rs @@ -86,3 +86,8 @@ fn read_pdf(data: Vec) -> File { ), } } + +/// Remove the first character of a string +pub fn remove_first_letter(s: &str) -> &str { + s.chars().next().map(|c| &s[c.len_utf8()..]).unwrap() +}