This commit is contained in:
parent
f2359be6a3
commit
9b9065eb1c
1 changed files with 41 additions and 7 deletions
|
@ -52,9 +52,9 @@ pub fn get_options() -> ComrakOptions {
|
||||||
hardbreaks: false, // could be true? change by metadata could be good for compatibility
|
hardbreaks: false, // could be true? change by metadata could be good for compatibility
|
||||||
github_pre_lang: false,
|
github_pre_lang: false,
|
||||||
full_info_string: true,
|
full_info_string: true,
|
||||||
width: 0, // 0 mean disabled?
|
width: 0, // 0 mean disabled?
|
||||||
unsafe_: true,
|
unsafe_: false, // could be true? change by metadata could be good for compatibility
|
||||||
escape: false, // may change in the future?
|
escape: false, // may change in the future?
|
||||||
list_style: ListStyleType::Dash,
|
list_style: ListStyleType::Dash,
|
||||||
sourcepos: false,
|
sourcepos: false,
|
||||||
},
|
},
|
||||||
|
@ -64,11 +64,11 @@ pub fn get_options() -> ComrakOptions {
|
||||||
pub fn read(raw_text: &str) -> File {
|
pub fn read(raw_text: &str) -> File {
|
||||||
let arena = Arena::new();
|
let arena = Arena::new();
|
||||||
|
|
||||||
// LaTeX conversion to MathML
|
|
||||||
let text = latex2mathml::replace(raw_text).unwrap_or_default();
|
|
||||||
|
|
||||||
let options = get_options();
|
let options = get_options();
|
||||||
let root = parse_document(&arena, &text, &options);
|
let root = parse_document(&arena, raw_text, &options);
|
||||||
|
|
||||||
|
// LaTeX conversion to MathML
|
||||||
|
latex_replace(root);
|
||||||
|
|
||||||
// Find metadata
|
// Find metadata
|
||||||
let metadata = get_metadata(root);
|
let metadata = get_metadata(root);
|
||||||
|
@ -135,3 +135,37 @@ fn check_code<'a>(root: &'a AstNode<'a>, blacklist: &[String]) -> bool {
|
||||||
_ => false,
|
_ => 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
|
||||||
|
_ => (),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue