This commit is contained in:
parent
e2e2e28461
commit
e75d900935
1 changed files with 9 additions and 7 deletions
|
@ -62,6 +62,7 @@ pub fn get_options() -> ComrakOptions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Transform markdown string to File structure
|
||||
pub fn read(raw_text: &str) -> File {
|
||||
let arena = Arena::new();
|
||||
|
||||
|
@ -76,15 +77,16 @@ pub fn read(raw_text: &str) -> File {
|
|||
format_html(root, &options, &mut html).unwrap();
|
||||
|
||||
let mermaid_name = "mermaid";
|
||||
let html_content = String::from_utf8(html).unwrap();
|
||||
|
||||
File {
|
||||
metadata: Metadata {
|
||||
info: metadata,
|
||||
mermaid: check_mermaid(root, mermaid_name.to_owned()),
|
||||
syntax_highlight: check_code(root, &[mermaid_name.to_owned()]),
|
||||
math: check_math(root),
|
||||
math: check_math(&html_content),
|
||||
},
|
||||
content: String::from_utf8(html).unwrap(),
|
||||
content: html_content,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +114,7 @@ pub fn get_metadata<'a>(root: &'a AstNode<'a>) -> FileMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
/// Recursively check whether mermaid diagrams are in the AST
|
||||
/// Check whether mermaid diagrams are in the AST
|
||||
fn check_mermaid<'a>(root: &'a AstNode<'a>, mermaid_str: String) -> bool {
|
||||
root.children().any(|node| match &node.data.borrow().value {
|
||||
// Check if code of block define a mermaid diagram
|
||||
|
@ -121,7 +123,7 @@ fn check_mermaid<'a>(root: &'a AstNode<'a>, mermaid_str: String) -> bool {
|
|||
})
|
||||
}
|
||||
|
||||
/// Recursively check if code is in the AST
|
||||
/// Check if code is in the AST
|
||||
fn check_code<'a>(root: &'a AstNode<'a>, blacklist: &[String]) -> bool {
|
||||
root.children().any(|node| match &node.data.borrow().value {
|
||||
// Detect code in paragraph
|
||||
|
@ -135,7 +137,7 @@ fn check_code<'a>(root: &'a AstNode<'a>, blacklist: &[String]) -> bool {
|
|||
})
|
||||
}
|
||||
|
||||
/// Check recursively if maths is in the AST
|
||||
fn check_math<'a>(root: &'a AstNode<'a>) -> bool {
|
||||
root.children().any(|_node| false)
|
||||
/// Check if html can contains maths
|
||||
fn check_math(html: &str) -> bool {
|
||||
html.contains('$')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue