From faab49a3858074b0c685b15c84e94f7624e2f8ee Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 1 Apr 2024 15:55:53 +0200 Subject: [PATCH] do not render footnote on embeded markdown files --- src/misc/markdown.rs | 27 +++++++++++++++++++++------ src/misc/utils.rs | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/misc/markdown.rs b/src/misc/markdown.rs index d12715a..69b3c3c 100644 --- a/src/misc/markdown.rs +++ b/src/misc/markdown.rs @@ -2,7 +2,7 @@ use crate::misc::date::Date; use base64::engine::general_purpose; use base64::Engine; use comrak::nodes::{AstNode, NodeValue}; -use comrak::{format_html, parse_document, Arena, ComrakOptions, ListStyleType}; +use comrak::{format_html, parse_document, Arena, ComrakOptions, ListStyleType, Options}; use lol_html::html_content::ContentType; use lol_html::{element, rewrite_str, HtmlRewriter, RewriteStrSettings, Settings}; use ramhorns::Content; @@ -227,7 +227,14 @@ fn fix_images_and_integration(path: &str, html: String) -> (String, Metadata) { if let Ok(file) = fs::read_to_string(&img_path) { let mime = mime_guess::from_path(&img_path).first_or_octet_stream(); if mime == "text/markdown" { - let data = read_md(&img_path, &file, TypeFileMetadata::Generic); + let mut options = get_options(); + options.extension.footnotes = false; + let data = read_md( + &img_path, + &file, + TypeFileMetadata::Generic, + Some(options), + ); el.replace(&data.content, ContentType::Html); metadata.merge(data.metadata); } else { @@ -250,11 +257,19 @@ fn fix_images_and_integration(path: &str, html: String) -> (String, Metadata) { } /// Transform markdown string to File structure -pub fn read_md(path: &str, raw_text: &str, metadata_type: TypeFileMetadata) -> File { +pub fn read_md( + path: &str, + raw_text: &str, + metadata_type: TypeFileMetadata, + options: Option, +) -> File { let arena = Arena::new(); - let options = get_options(); - let root = parse_document(&arena, raw_text, &options); + let opt = match options { + Some(specific_opt) => specific_opt, + None => get_options(), + }; + let root = parse_document(&arena, raw_text, &opt); // Find metadata let metadata = get_metadata(root, metadata_type); @@ -264,7 +279,7 @@ pub fn read_md(path: &str, raw_text: &str, metadata_type: TypeFileMetadata) -> F // Convert to HTML let mut html = vec![]; - format_html(root, &options, &mut html).unwrap(); + format_html(root, &opt, &mut html).unwrap(); let mut html_content = String::from_utf8(html).unwrap(); diff --git a/src/misc/utils.rs b/src/misc/utils.rs index 0b3dec5..da27dec 100644 --- a/src/misc/utils.rs +++ b/src/misc/utils.rs @@ -61,7 +61,7 @@ pub fn read_file(filename: &str, expected_file: TypeFileMetadata) -> Option None, }, _ => match fs::read_to_string(filename) { - Ok(text) => Some(read_md(filename, &text, expected_file)), + Ok(text) => Some(read_md(filename, &text, expected_file, None)), Err(_) => None, }, },