split into proper function
This commit is contained in:
parent
2df93e5c99
commit
8de0c4ca04
2 changed files with 7 additions and 6 deletions
|
@ -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(())
|
||||
|
|
|
@ -86,3 +86,8 @@ fn read_pdf(data: Vec<u8>) -> 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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue