diff options
author | Vincent Ambo <mail@tazj.in> | 2023-06-06T11·26+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2023-06-06T11·43+0000 |
commit | 5dee4780dab5e22eb2929a3b4287c5a781fc20f9 (patch) | |
tree | efdbcdd87bef1bd6dcca3010c0b7115bb443b6de /corp/rih/frontend/static-markdown | |
parent | 6fa6f3a7f4a72a74ce495609646d2dae3789cde3 (diff) |
chore(corp/rih): move frontend to a separate folder r/6237
Change-Id: Ic7467f459015c39c73f87c61a048319eaf1243be Reviewed-on: https://cl.tvl.fyi/c/depot/+/8714 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'corp/rih/frontend/static-markdown')
-rw-r--r-- | corp/rih/frontend/static-markdown/Cargo.toml | 12 | ||||
-rw-r--r-- | corp/rih/frontend/static-markdown/src/lib.rs | 27 |
2 files changed, 39 insertions, 0 deletions
diff --git a/corp/rih/frontend/static-markdown/Cargo.toml b/corp/rih/frontend/static-markdown/Cargo.toml new file mode 100644 index 000000000000..c0e298d44cf2 --- /dev/null +++ b/corp/rih/frontend/static-markdown/Cargo.toml @@ -0,0 +1,12 @@ +[package] +version = "1.0.0" +name = "static_markdown" +edition = "2018" + +[lib] +proc-macro = true + +[dependencies] +syn = "1.0" +quote = "1.0" +comrak = "0.18" diff --git a/corp/rih/frontend/static-markdown/src/lib.rs b/corp/rih/frontend/static-markdown/src/lib.rs new file mode 100644 index 000000000000..6a25c9292654 --- /dev/null +++ b/corp/rih/frontend/static-markdown/src/lib.rs @@ -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() +} |