ggdgsdbsdbbb / markdown / html.v
25 lines · 19 sloc · 774 bytes · 8dec386d5f65c9eed2c7c24c74374dee9d07525f
Raw
1module markdown
2
3import strings
4
5fn C.md_html(const_input &char, input_size u32, process_output ProcessFn, userdata voidptr, parser_flags u32, renderer_flags u32) int
6
7const need_html_esc_flag = 0x1
8const need_url_esc_flag = 0x2
9const md_html_flag_debug = 0x0001
10const md_html_flag_verbatim_entities = 0x0002
11const md_html_flag_skip_utf8_bom = 0x0004
12
13type ProcessFn = fn (const_t &char, s u32, x voidptr)
14
15fn write_data_cb(const_txt &char, size u32, userdata voidptr) {
16 s := unsafe { tos(&u8(const_txt), int(size)) }
17 mut sb := unsafe { &strings.Builder(userdata) }
18 sb.write_string(s)
19}
20
21pub fn to_html(input string) string {
22 mut wr := strings.new_builder(200)
23 C.md_html(input.str, input.len, write_data_cb, &wr, C.MD_DIALECT_GITHUB, 0)
24 return wr.str().trim_space()
25}
26