From 41311c05edc4ca4eeb7c72cec03079dbcc800eb4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 13 Dec 2024 18:11:55 +0100 Subject: [PATCH] have a unique header id per file currently this break anchors as id != links --- src/utils/markdown.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/utils/markdown.rs b/src/utils/markdown.rs index e051a12..f0cacb9 100644 --- a/src/utils/markdown.rs +++ b/src/utils/markdown.rs @@ -59,7 +59,10 @@ pub fn get_options(path: Option, metadata_type: MType) -> ComrakOption .autolink(true) .tasklist(true) .superscript(true) - .header_ids(String::new()) + .header_ids(match path.clone() { + Some(fp) => format!("{}-", fp.path.get(..fp.path.len() - 3).unwrap_or_default()), + None => String::new(), + }) .footnotes(true) .description_lists(true) .front_matter_delimiter("---".into()) @@ -220,7 +223,21 @@ fn fix_images_and_integration( let mime = mime_guess::from_path(&img_path).first_or_octet_stream(); if recursive && mime == "text/markdown" { let file_str = String::from_utf8_lossy(&file_contents).into_owned(); - let mut options = get_options(Some(path.clone()), metadata_type); + + // Find a ok-ish path + let new_path = img_path.split('/'); + let mut options = get_options( + Some(FilePath { + base: new_path + .clone() + .take(new_path.clone().count() - 1) + .collect::>() + .join("/"), + path: new_path.last().unwrap_or("").to_string(), + }), + metadata_type, + ); + options.extension.footnotes = false; let data = read_md( &path.from(&img_path),