about summary refs log tree commit diff
path: root/corp/rih/static-markdown/src/lib.rs
blob: 6a25c929265427eb26d7ad18358cb9c1a10fd869 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()
}