ggdgsdbsdbbb / markdown / md4c.v
172 lines · 149 sloc · 2.81 KB · 8dec386d5f65c9eed2c7c24c74374dee9d07525f
Raw
1module markdown
2
3#flag -I @VMODROOT/thirdparty/md4c
4#flag @VMODROOT/thirdparty/md4c-lib.c
5#include "md4c.h"
6#include "md4c-html.h"
7
8type BlockFn = fn (t MD_BLOCKTYPE, d voidptr, u voidptr) int
9
10type SpanFn = fn (t MD_SPANTYPE, d voidptr, u voidptr) int
11
12type TextFn = fn (t MD_TEXTTYPE, tx &char, s u32, u voidptr) int
13
14type DebugFn = fn (m &char, u voidptr)
15
16@[typedef]
17pub enum MD_BLOCKTYPE {
18 md_block_doc = 0
19 md_block_quote
20 md_block_ul
21 md_block_ol
22 md_block_li
23 md_block_hr
24 md_block_h
25 md_block_code
26 md_block_html
27 md_block_p
28 md_block_table
29 md_block_thead
30 md_block_tbody
31 md_block_tr
32 md_block_th
33 md_block_td
34}
35
36@[typedef]
37pub enum MD_TEXTTYPE {
38 md_text_normal = 0
39 md_text_null_char
40 md_text_br
41 md_text_softbr
42 md_text_entity
43 md_text_code
44 md_text_html
45 md_text_latexmath
46}
47
48@[typedef]
49pub enum MD_SPANTYPE {
50 md_span_em
51 md_span_strong
52 md_span_a
53 md_span_img
54 md_span_code
55 md_span_del
56 md_span_latexmath
57 md_span_latexmath_display
58 md_span_wikilink
59 md_span_u
60}
61
62@[typedef]
63pub enum MD_ALIGN {
64 md_align_default = 0
65 md_align_left
66 md_align_center
67 md_align_right
68}
69
70@[typedef]
71pub struct C.MD_PARSER {
72pub:
73 abi_version u32
74 flags u32
75 enter_block BlockFn
76 leave_block BlockFn
77 enter_span SpanFn
78 leave_span SpanFn
79 text TextFn
80 debug_log DebugFn
81}
82
83@[typedef]
84pub struct C.MD_ATTRIBUTE {
85pub:
86 text &char
87 size u32
88 substr_types &MD_TEXTTYPE
89 substr_offsets &u32
90}
91
92@[typedef]
93pub struct C.MD_BLOCK_UL_DETAIL {
94pub:
95 is_tight int
96 mark u8
97}
98
99@[typedef]
100pub struct C.MD_BLOCK_OL_DETAIL {
101pub:
102 start u32
103 is_tight int
104 mark_delimiter u8
105}
106
107@[typedef]
108pub struct C.MD_BLOCK_LI_DETAIL {
109pub:
110 is_task bool
111 task_mark u8
112 task_mark_offset u32
113}
114
115@[typedef]
116pub struct C.MD_BLOCK_H_DETAIL {
117pub:
118 level u32
119}
120
121@[typedef]
122pub struct C.MD_BLOCK_CODE_DETAIL {
123pub:
124 info C.MD_ATTRIBUTE
125 lang C.MD_ATTRIBUTE
126 fence_char u8
127}
128
129@[typedef]
130pub struct C.MD_BLOCK_TD_DETAIL {
131pub:
132 align MD_ALIGN
133}
134
135@[typedef]
136pub struct C.MD_SPAN_A_DETAIL {
137pub:
138 href C.MD_ATTRIBUTE
139 title C.MD_ATTRIBUTE
140}
141
142@[typedef]
143pub struct C.MD_SPAN_IMG_DETAIL {
144pub:
145 src C.MD_ATTRIBUTE
146 title C.MD_ATTRIBUTE
147}
148
149@[typedef]
150pub struct C.MD_SPAN_WIKILINK_DETAIL {
151pub:
152 target C.MD_ATTRIBUTE
153}
154
155fn C.md_parse(text &char, size u32, parser &C.MD_PARSER, userdata voidptr) int
156
157pub fn new(parser_flags u32, enter_block_cb BlockFn, leave_block_cb BlockFn, enter_span_cb SpanFn, leave_span_cb SpanFn, text_cb TextFn, debug_cb DebugFn) C.MD_PARSER {
158 return C.MD_PARSER{
159 abi_version: 0
160 flags: parser_flags
161 enter_block: enter_block_cb
162 leave_block: leave_block_cb
163 enter_span: enter_span_cb
164 leave_span: leave_span_cb
165 text: text_cb
166 debug_log: debug_cb
167 }
168}
169
170fn parse(text &char, size u32, parser &C.MD_PARSER, userdata voidptr) int {
171 return C.md_parse(text, size, parser, userdata)
172}
173