Reorganize
This commit is contained in:
106
crates/service/service-webpage/src/components/md.rs
Normal file
106
crates/service/service-webpage/src/components/md.rs
Normal file
@@ -0,0 +1,106 @@
|
||||
use markdown::{CompileOptions, Constructs, LineEnding, Options, ParseOptions};
|
||||
use maud::{Markup, PreEscaped, Render};
|
||||
|
||||
pub struct Markdown<'a>(pub &'a str);
|
||||
|
||||
const OPTS: Options = Options {
|
||||
parse: ParseOptions {
|
||||
constructs: Constructs {
|
||||
attention: true,
|
||||
autolink: false,
|
||||
block_quote: true,
|
||||
character_escape: true,
|
||||
character_reference: true,
|
||||
code_indented: false,
|
||||
code_fenced: true,
|
||||
code_text: true,
|
||||
definition: true,
|
||||
frontmatter: false,
|
||||
gfm_autolink_literal: true,
|
||||
gfm_footnote_definition: false,
|
||||
gfm_label_start_footnote: false,
|
||||
gfm_strikethrough: false,
|
||||
gfm_table: false,
|
||||
gfm_task_list_item: false,
|
||||
hard_break_escape: false,
|
||||
hard_break_trailing: false,
|
||||
heading_atx: true,
|
||||
heading_setext: false,
|
||||
label_start_image: false,
|
||||
label_start_link: true,
|
||||
label_end: true,
|
||||
list_item: true,
|
||||
math_flow: false,
|
||||
math_text: false,
|
||||
mdx_esm: false,
|
||||
thematic_break: false,
|
||||
|
||||
// INLINE HTML
|
||||
html_flow: false,
|
||||
html_text: false,
|
||||
|
||||
// INLINE {}
|
||||
mdx_expression_flow: true,
|
||||
mdx_expression_text: true,
|
||||
|
||||
// INLINE HTML (alternative)
|
||||
mdx_jsx_flow: false,
|
||||
mdx_jsx_text: false,
|
||||
},
|
||||
|
||||
gfm_strikethrough_single_tilde: false,
|
||||
math_text_single_dollar: false,
|
||||
mdx_expression_parse: None,
|
||||
mdx_esm_parse: None,
|
||||
},
|
||||
|
||||
compile: CompileOptions {
|
||||
allow_any_img_src: false,
|
||||
allow_dangerous_html: false,
|
||||
allow_dangerous_protocol: false,
|
||||
default_line_ending: LineEnding::LineFeed,
|
||||
gfm_footnote_back_label: None,
|
||||
gfm_footnote_clobber_prefix: None,
|
||||
gfm_footnote_label_attributes: None,
|
||||
gfm_footnote_label_tag_name: None,
|
||||
gfm_footnote_label: None,
|
||||
gfm_task_list_item_checkable: false,
|
||||
gfm_tagfilter: false,
|
||||
},
|
||||
};
|
||||
|
||||
impl Render for Markdown<'_> {
|
||||
fn render(&self) -> Markup {
|
||||
/*
|
||||
let mut ast = markdown::to_mdast(MD_A, &opts.parse).unwrap();
|
||||
let walk = AstWalkMut::new(&mut ast);
|
||||
|
||||
for i in walk {
|
||||
match i {
|
||||
AstWalkMutStep::Exit(node) => {
|
||||
match node {
|
||||
Node::MdxTextExpression(x) => {
|
||||
println!("{x:?}");
|
||||
}
|
||||
Node::MdxFlowExpression(x) => {
|
||||
println!("{x:?}");
|
||||
}
|
||||
_ => continue,
|
||||
}
|
||||
|
||||
*node = Node::Text(Text {
|
||||
value: "LOL".to_owned(),
|
||||
position: node.position().cloned(),
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
println!("{ast:?}");
|
||||
*/
|
||||
|
||||
let md = markdown::to_html_with_options(self.0, &OPTS).unwrap();
|
||||
return PreEscaped(md);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user