do not render footnote on embeded markdown files
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending approval

This commit is contained in:
Mylloon 2024-04-01 15:55:53 +02:00
parent c6ff926f02
commit faab49a385
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 22 additions and 7 deletions

View file

@ -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<Options>,
) -> 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();

View file

@ -61,7 +61,7 @@ pub fn read_file(filename: &str, expected_file: TypeFileMetadata) -> Option<File
Err(_) => 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,
},
},