diff --git a/src/misc/markdown.rs b/src/misc/markdown.rs index 439b6cb..0e84049 100644 --- a/src/misc/markdown.rs +++ b/src/misc/markdown.rs @@ -52,9 +52,9 @@ pub fn get_options() -> ComrakOptions { hardbreaks: false, // could be true? change by metadata could be good for compatibility github_pre_lang: false, full_info_string: true, - width: 0, // 0 mean disabled? - unsafe_: false, // could be true? change by metadata could be good for compatibility - escape: false, // may change in the future? + width: 0, // 0 mean disabled? + unsafe_: true, + escape: false, // may change in the future? list_style: ListStyleType::Dash, sourcepos: false, }, @@ -64,11 +64,11 @@ pub fn get_options() -> ComrakOptions { pub fn read(raw_text: &str) -> File { let arena = Arena::new(); - let options = get_options(); - let root = parse_document(&arena, raw_text, &options); - // LaTeX conversion to MathML - latex_replace(root); + let text = latex2mathml::replace(raw_text).unwrap_or_default(); + + let options = get_options(); + let root = parse_document(&arena, &text, &options); // Find metadata let metadata = get_metadata(root); @@ -135,37 +135,3 @@ fn check_code<'a>(root: &'a AstNode<'a>, blacklist: &[String]) -> bool { _ => false, }) } - -/// Call the `latex2mathml::replace` function when LaTeX formula can appears -/// without breaking things -fn latex_replace<'a>(root: &'a AstNode<'a>) { - root.children() - .for_each(|node| match &mut node.data.borrow_mut().value { - // Detect in blocks - NodeValue::Paragraph - | NodeValue::BlockQuote - | NodeValue::TableCell - - // Detect in inlines - | NodeValue::Emph - | NodeValue::Strong - | NodeValue::Strikethrough - | NodeValue::Superscript => { - latex_replace(node) - } - - // Contains text - NodeValue::Text(ref mut text) => { - *text = latex2mathml::replace(text).unwrap_or(text.to_owned()) - }, - NodeValue::Link(ref mut link) | NodeValue::Image(ref mut link) => { - let mut clone = link.clone(); - clone.title = latex2mathml::replace(&link.title).unwrap_or(clone.title); - - *link = clone; - }, - - // Everything not captured can't contains math - _ => (), - }); -}