have a unique header id per file

currently this break anchors as id != links
This commit is contained in:
Mylloon 2024-12-13 18:11:55 +01:00
parent 7752363039
commit 41311c05ed
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -59,7 +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(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) .footnotes(true)
.description_lists(true) .description_lists(true)
.front_matter_delimiter("---".into()) .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(); let mime = mime_guess::from_path(&img_path).first_or_octet_stream();
if recursive && mime == "text/markdown" { if recursive && mime == "text/markdown" {
let file_str = String::from_utf8_lossy(&file_contents).into_owned(); 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::<Vec<_>>()
.join("/"),
path: new_path.last().unwrap_or("").to_string(),
}),
metadata_type,
);
options.extension.footnotes = false; options.extension.footnotes = false;
let data = read_md( let data = read_md(
&path.from(&img_path), &path.from(&img_path),