fix header ids not in sync with the link
This commit is contained in:
parent
41311c05ed
commit
f72a341787
1 changed files with 20 additions and 2 deletions
|
@ -59,8 +59,10 @@ pub fn get_options(path: Option<FilePath>, metadata_type: MType) -> ComrakOption
|
||||||
.autolink(true)
|
.autolink(true)
|
||||||
.tasklist(true)
|
.tasklist(true)
|
||||||
.superscript(true)
|
.superscript(true)
|
||||||
.header_ids(match path.clone() {
|
.header_ids(match path {
|
||||||
Some(fp) => format!("{}-", fp.path.get(..fp.path.len() - 3).unwrap_or_default()),
|
Some(ref fp) => {
|
||||||
|
format!("{}-", fp.path.get(..fp.path.len() - 3).unwrap_or_default())
|
||||||
|
}
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
})
|
})
|
||||||
.footnotes(true)
|
.footnotes(true)
|
||||||
|
@ -190,6 +192,21 @@ fn custom_img_size(html: &str) -> String {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fix_headers_ids(html: &str) -> String {
|
||||||
|
rewrite_str(
|
||||||
|
html,
|
||||||
|
RewriteStrSettings {
|
||||||
|
element_content_handlers: vec![element!("a[href^='#']", |el| {
|
||||||
|
el.set_attribute("href", &format!("#{}", el.get_attribute("id").unwrap()))
|
||||||
|
.unwrap();
|
||||||
|
Ok(())
|
||||||
|
})],
|
||||||
|
..RewriteStrSettings::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
/// Fix local images to base64 and integration of markdown files
|
/// Fix local images to base64 and integration of markdown files
|
||||||
fn fix_images_and_integration(
|
fn fix_images_and_integration(
|
||||||
path: &FilePath,
|
path: &FilePath,
|
||||||
|
@ -308,6 +325,7 @@ pub fn read_md(
|
||||||
(html_content, children_metadata) =
|
(html_content, children_metadata) =
|
||||||
fix_images_and_integration(path, &html_content, metadata_type, recursive);
|
fix_images_and_integration(path, &html_content, metadata_type, recursive);
|
||||||
html_content = custom_img_size(&html_content);
|
html_content = custom_img_size(&html_content);
|
||||||
|
html_content = fix_headers_ids(&html_content);
|
||||||
(html_content, mail_obfsucated) = mail_obfuscation(&html_content);
|
(html_content, mail_obfsucated) = mail_obfuscation(&html_content);
|
||||||
|
|
||||||
let mut final_metadata = Metadata {
|
let mut final_metadata = Metadata {
|
||||||
|
|
Loading…
Reference in a new issue