feat(corp/rih): add macro to render Markdown->yew::Html statically
This makes it possible to embed long texts from Markdown files instead of dealing with writing the weird HTML-tags inside the yew macros, which will be much easier for content editors to deal with. Change-Id: Idc4e67404fcfe2b8d5083cf556df1c701ba17660 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8648 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
99c7896637
commit
d419b81ef7
5 changed files with 518 additions and 0 deletions
27
corp/rih/static-markdown/src/lib.rs
Normal file
27
corp/rih/static-markdown/src/lib.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
extern crate proc_macro;
|
||||
|
||||
use comrak::{markdown_to_html, ComrakOptions};
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, LitStr};
|
||||
|
||||
#[proc_macro]
|
||||
pub fn markdown(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as LitStr);
|
||||
|
||||
let mut options = ComrakOptions::default();
|
||||
options.extension.strikethrough = true;
|
||||
options.extension.tagfilter = true;
|
||||
options.extension.table = true;
|
||||
options.extension.autolink = true;
|
||||
|
||||
let rendered_html = markdown_to_html(&input.value(), &options);
|
||||
|
||||
let tokens = quote! {
|
||||
yew::virtual_dom::VNode::VRaw(yew::virtual_dom::VRaw {
|
||||
html: #rendered_html.into(),
|
||||
})
|
||||
};
|
||||
|
||||
tokens.into()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue