fix stack overflow
This commit is contained in:
parent
e9d7e9d14c
commit
533d2c1044
2 changed files with 20 additions and 6 deletions
|
@ -104,7 +104,12 @@ fn custom_img_size(html: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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(path: &str, html: &str) -> (String, Metadata) {
|
fn fix_images_and_integration(
|
||||||
|
path: &str,
|
||||||
|
html: &str,
|
||||||
|
metadata_type: MType,
|
||||||
|
recursive: bool,
|
||||||
|
) -> (String, Metadata) {
|
||||||
let mut metadata = Metadata {
|
let mut metadata = Metadata {
|
||||||
info: MFile::default(),
|
info: MFile::default(),
|
||||||
math: false,
|
math: false,
|
||||||
|
@ -125,12 +130,14 @@ fn fix_images_and_integration(path: &str, html: &str) -> (String, Metadata) {
|
||||||
let img_path = urlencoding::decode(img_src.join(src).to_str().unwrap())
|
let img_path = urlencoding::decode(img_src.join(src).to_str().unwrap())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
if let Ok(file) = fs::read_to_string(&img_path) {
|
if let Ok(file) = fs::read_to_string(&img_path) {
|
||||||
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 mime == "text/markdown" {
|
if recursive && mime == "text/markdown" {
|
||||||
let mut options = get_options();
|
let mut options = get_options();
|
||||||
options.extension.footnotes = false;
|
options.extension.footnotes = false;
|
||||||
let data = read_md(&img_path, &file, MType::Generic, Some(options));
|
let data =
|
||||||
|
read_md(&img_path, &file, metadata_type, Some(options), false);
|
||||||
el.replace(&data.content, ContentType::Html);
|
el.replace(&data.content, ContentType::Html);
|
||||||
|
|
||||||
// Store the metadata for later merging
|
// Store the metadata for later merging
|
||||||
|
@ -158,7 +165,13 @@ fn fix_images_and_integration(path: &str, html: &str) -> (String, Metadata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transform markdown string to File structure
|
/// Transform markdown string to File structure
|
||||||
pub fn read_md(path: &str, raw_text: &str, metadata_type: MType, options: Option<Options>) -> File {
|
pub fn read_md(
|
||||||
|
path: &str,
|
||||||
|
raw_text: &str,
|
||||||
|
metadata_type: MType,
|
||||||
|
options: Option<Options>,
|
||||||
|
recursive: bool,
|
||||||
|
) -> File {
|
||||||
let arena = Arena::new();
|
let arena = Arena::new();
|
||||||
|
|
||||||
let mut opt = options.map_or_else(get_options, |specific_opt| specific_opt);
|
let mut opt = options.map_or_else(get_options, |specific_opt| specific_opt);
|
||||||
|
@ -181,7 +194,8 @@ pub fn read_md(path: &str, raw_text: &str, metadata_type: MType, options: Option
|
||||||
|
|
||||||
let children_metadata;
|
let children_metadata;
|
||||||
let mail_obfsucated;
|
let mail_obfsucated;
|
||||||
(html_content, children_metadata) = fix_images_and_integration(path, &html_content);
|
(html_content, children_metadata) =
|
||||||
|
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, mail_obfsucated) = mail_obfuscation(&html_content);
|
(html_content, mail_obfsucated) = mail_obfuscation(&html_content);
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub fn read_file(filename: String, expected_file: MType) -> Option<File> {
|
||||||
.and_then(|ext| match ext.to_str().unwrap() {
|
.and_then(|ext| match ext.to_str().unwrap() {
|
||||||
"pdf" => fs::read(filename).map_or(None, |bytes| Some(read_pdf(bytes))),
|
"pdf" => fs::read(filename).map_or(None, |bytes| Some(read_pdf(bytes))),
|
||||||
_ => fs::read_to_string(&filename).map_or(None, |text| {
|
_ => fs::read_to_string(&filename).map_or(None, |text| {
|
||||||
Some(read_md(&filename, &text, expected_file, None))
|
Some(read_md(&filename, &text, expected_file, None, true))
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue