1use crate::lexer::lexer::lexer::Lexer;
6extern crate wasm_bindgen;
7use wasm_bindgen::prelude::*;
8
9mod lexer;
10mod util;
11
12#[cfg(feature = "wee_alloc")]
13#[global_allocator]
14static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
15
16#[wasm_bindgen]
18pub struct FlavMd {
19 html_text: String,
21 css_text: String,
25}
26
27#[wasm_bindgen]
29impl FlavMd {
30 #[wasm_bindgen(constructor)]
34 pub fn new() -> Self {
35 FlavMd {
36 html_text: "".to_string(),
37 css_text: "".to_string(),
38 }
39 }
40
41 pub fn build(&mut self, md_text: String, css_text: String) -> String {
43 let lexer = Lexer::new(md_text.split("\n").map(|s| s.to_string()).collect());
44 self.html_text = lexer.parse().to_html_string();
45 self.css_text = css_text;
46 format!("<style>{}</style>\n{}", self.css_text, self.html_text)
47 }
48}
49
50#[wasm_bindgen]
69pub fn create_flav_md() -> FlavMd {
70 FlavMd::new()
71}
72
73#[cfg(test)]
74mod test {
75 use crate::create_flav_md;
76
77 #[test]
78 fn correctly_build_file() {
79 let html_text = "<h1 class=\"flav-md-text flav-md-h1 flav-md-h\">sample</h1>".to_string();
80 let css_text = r#".flav-md-h1 {
81 color: red;
82}"#
83 .to_string();
84 let expected = format!("<style>{}</style>\n{}", css_text, html_text);
85 let actual = create_flav_md().build("# sample".to_string(), css_text);
86 assert_eq!(actual, expected);
87 }
88}