commonmarker 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of commonmarker might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/commonmarker/cmark/CMakeLists.txt +10 -4
- data/ext/commonmarker/cmark/Makefile +5 -5
- data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/api_test/main.c +16 -0
- data/ext/commonmarker/cmark/build/CMakeCache.txt +3 -4
- data/ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CMakeSystem.cmake +4 -4
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +12 -12
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +97 -142
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +0 -1
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +1 -1
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +23 -23
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +2 -2
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/buffer.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_u.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/references.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/render.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/utf8.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/cmake_install.cmake +3 -3
- data/ext/commonmarker/cmark/build/src/cmark_version.h +2 -2
- data/ext/commonmarker/cmark/build/src/config.h +6 -6
- data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.pc +1 -1
- data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +4 -4
- data/ext/commonmarker/cmark/changelog.txt +46 -0
- data/ext/commonmarker/cmark/man/man3/cmark.3 +21 -20
- data/ext/commonmarker/cmark/src/CMakeLists.txt +4 -6
- data/ext/commonmarker/cmark/src/bench.h +8 -8
- data/ext/commonmarker/cmark/src/blocks.c +917 -947
- data/ext/commonmarker/cmark/src/buffer.c +213 -288
- data/ext/commonmarker/cmark/src/buffer.h +19 -21
- data/ext/commonmarker/cmark/src/chunk.h +78 -82
- data/ext/commonmarker/cmark/src/cmark.c +9 -17
- data/ext/commonmarker/cmark/src/cmark.h +113 -157
- data/ext/commonmarker/cmark/src/cmark_ctype.c +24 -35
- data/ext/commonmarker/cmark/src/commonmark.c +390 -425
- data/ext/commonmarker/cmark/src/config.h.in +6 -6
- data/ext/commonmarker/cmark/src/houdini.h +21 -15
- data/ext/commonmarker/cmark/src/houdini_href_e.c +50 -57
- data/ext/commonmarker/cmark/src/houdini_html_e.c +36 -51
- data/ext/commonmarker/cmark/src/houdini_html_u.c +119 -124
- data/ext/commonmarker/cmark/src/html.c +289 -307
- data/ext/commonmarker/cmark/src/inlines.c +976 -1030
- data/ext/commonmarker/cmark/src/inlines.h +4 -2
- data/ext/commonmarker/cmark/src/iterator.c +96 -126
- data/ext/commonmarker/cmark/src/iterator.h +5 -5
- data/ext/commonmarker/cmark/src/latex.c +379 -401
- data/ext/commonmarker/cmark/src/main.c +168 -175
- data/ext/commonmarker/cmark/src/man.c +212 -226
- data/ext/commonmarker/cmark/src/node.c +746 -839
- data/ext/commonmarker/cmark/src/node.h +47 -48
- data/ext/commonmarker/cmark/src/parser.h +14 -14
- data/ext/commonmarker/cmark/src/references.c +101 -111
- data/ext/commonmarker/cmark/src/references.h +10 -8
- data/ext/commonmarker/cmark/src/render.c +144 -167
- data/ext/commonmarker/cmark/src/render.h +22 -41
- data/ext/commonmarker/cmark/src/scanners.c +27695 -20903
- data/ext/commonmarker/cmark/src/scanners.h +2 -1
- data/ext/commonmarker/cmark/src/scanners.re +1 -1
- data/ext/commonmarker/cmark/src/utf8.c +276 -419
- data/ext/commonmarker/cmark/src/utf8.h +6 -6
- data/ext/commonmarker/cmark/src/xml.c +129 -144
- data/ext/commonmarker/cmark/test/CMakeLists.txt +4 -4
- data/ext/commonmarker/cmark/test/smart_punct.txt +8 -0
- data/ext/commonmarker/cmark/test/spec.txt +109 -47
- data/lib/commonmarker/version.rb +1 -1
- metadata +2 -2
@@ -12,322 +12,304 @@
|
|
12
12
|
|
13
13
|
// Functions to convert cmark_nodes to HTML strings.
|
14
14
|
|
15
|
-
static void escape_html(cmark_strbuf *dest, const unsigned char *source,
|
16
|
-
{
|
17
|
-
|
15
|
+
static void escape_html(cmark_strbuf *dest, const unsigned char *source,
|
16
|
+
bufsize_t length) {
|
17
|
+
houdini_escape_html0(dest, source, length, 0);
|
18
18
|
}
|
19
19
|
|
20
|
-
static inline void cr(cmark_strbuf *html)
|
21
|
-
|
22
|
-
|
23
|
-
cmark_strbuf_putc(html, '\n');
|
20
|
+
static inline void cr(cmark_strbuf *html) {
|
21
|
+
if (html->size && html->ptr[html->size - 1] != '\n')
|
22
|
+
cmark_strbuf_putc(html, '\n');
|
24
23
|
}
|
25
24
|
|
26
25
|
struct render_state {
|
27
|
-
|
28
|
-
|
26
|
+
cmark_strbuf *html;
|
27
|
+
cmark_node *plain;
|
29
28
|
};
|
30
29
|
|
31
|
-
static void
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
}
|
30
|
+
static void S_render_sourcepos(cmark_node *node, cmark_strbuf *html,
|
31
|
+
int options) {
|
32
|
+
char buffer[100];
|
33
|
+
if (CMARK_OPT_SOURCEPOS & options) {
|
34
|
+
sprintf(buffer, " data-sourcepos=\"%d:%d-%d:%d\"",
|
35
|
+
cmark_node_get_start_line(node), cmark_node_get_start_column(node),
|
36
|
+
cmark_node_get_end_line(node), cmark_node_get_end_column(node));
|
37
|
+
cmark_strbuf_puts(html, buffer);
|
38
|
+
}
|
41
39
|
}
|
42
40
|
|
43
|
-
static int
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
escape_html(html, node->as.link.title.data,
|
300
|
-
node->as.link.title.len);
|
301
|
-
}
|
302
|
-
|
303
|
-
cmark_strbuf_puts(html, "\" />");
|
304
|
-
}
|
305
|
-
break;
|
306
|
-
|
307
|
-
default:
|
308
|
-
assert(false);
|
309
|
-
break;
|
310
|
-
}
|
311
|
-
|
312
|
-
// cmark_strbuf_putc(html, 'x');
|
313
|
-
return 1;
|
41
|
+
static int S_render_node(cmark_node *node, cmark_event_type ev_type,
|
42
|
+
struct render_state *state, int options) {
|
43
|
+
cmark_node *parent;
|
44
|
+
cmark_node *grandparent;
|
45
|
+
cmark_strbuf *html = state->html;
|
46
|
+
char start_header[] = "<h0";
|
47
|
+
char end_header[] = "</h0";
|
48
|
+
bool tight;
|
49
|
+
char buffer[100];
|
50
|
+
|
51
|
+
bool entering = (ev_type == CMARK_EVENT_ENTER);
|
52
|
+
|
53
|
+
if (state->plain == node) { // back at original node
|
54
|
+
state->plain = NULL;
|
55
|
+
}
|
56
|
+
|
57
|
+
if (state->plain != NULL) {
|
58
|
+
switch (node->type) {
|
59
|
+
case CMARK_NODE_TEXT:
|
60
|
+
case CMARK_NODE_CODE:
|
61
|
+
case CMARK_NODE_INLINE_HTML:
|
62
|
+
escape_html(html, node->as.literal.data, node->as.literal.len);
|
63
|
+
break;
|
64
|
+
|
65
|
+
case CMARK_NODE_LINEBREAK:
|
66
|
+
case CMARK_NODE_SOFTBREAK:
|
67
|
+
cmark_strbuf_putc(html, ' ');
|
68
|
+
break;
|
69
|
+
|
70
|
+
default:
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
return 1;
|
74
|
+
}
|
75
|
+
|
76
|
+
switch (node->type) {
|
77
|
+
case CMARK_NODE_DOCUMENT:
|
78
|
+
break;
|
79
|
+
|
80
|
+
case CMARK_NODE_BLOCK_QUOTE:
|
81
|
+
if (entering) {
|
82
|
+
cr(html);
|
83
|
+
cmark_strbuf_puts(html, "<blockquote");
|
84
|
+
S_render_sourcepos(node, html, options);
|
85
|
+
cmark_strbuf_puts(html, ">\n");
|
86
|
+
} else {
|
87
|
+
cr(html);
|
88
|
+
cmark_strbuf_puts(html, "</blockquote>\n");
|
89
|
+
}
|
90
|
+
break;
|
91
|
+
|
92
|
+
case CMARK_NODE_LIST: {
|
93
|
+
cmark_list_type list_type = node->as.list.list_type;
|
94
|
+
int start = node->as.list.start;
|
95
|
+
|
96
|
+
if (entering) {
|
97
|
+
cr(html);
|
98
|
+
if (list_type == CMARK_BULLET_LIST) {
|
99
|
+
cmark_strbuf_puts(html, "<ul");
|
100
|
+
S_render_sourcepos(node, html, options);
|
101
|
+
cmark_strbuf_puts(html, ">\n");
|
102
|
+
} else if (start == 1) {
|
103
|
+
cmark_strbuf_puts(html, "<ol");
|
104
|
+
S_render_sourcepos(node, html, options);
|
105
|
+
cmark_strbuf_puts(html, ">\n");
|
106
|
+
} else {
|
107
|
+
sprintf(buffer, "<ol start=\"%d\"", start);
|
108
|
+
cmark_strbuf_puts(html, buffer);
|
109
|
+
S_render_sourcepos(node, html, options);
|
110
|
+
cmark_strbuf_puts(html, ">\n");
|
111
|
+
}
|
112
|
+
} else {
|
113
|
+
cmark_strbuf_puts(html,
|
114
|
+
list_type == CMARK_BULLET_LIST ? "</ul>\n" : "</ol>\n");
|
115
|
+
}
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
|
119
|
+
case CMARK_NODE_ITEM:
|
120
|
+
if (entering) {
|
121
|
+
cr(html);
|
122
|
+
cmark_strbuf_puts(html, "<li");
|
123
|
+
S_render_sourcepos(node, html, options);
|
124
|
+
cmark_strbuf_putc(html, '>');
|
125
|
+
} else {
|
126
|
+
cmark_strbuf_puts(html, "</li>\n");
|
127
|
+
}
|
128
|
+
break;
|
129
|
+
|
130
|
+
case CMARK_NODE_HEADER:
|
131
|
+
if (entering) {
|
132
|
+
cr(html);
|
133
|
+
start_header[2] = (char)('0' + node->as.header.level);
|
134
|
+
cmark_strbuf_puts(html, start_header);
|
135
|
+
S_render_sourcepos(node, html, options);
|
136
|
+
cmark_strbuf_putc(html, '>');
|
137
|
+
} else {
|
138
|
+
end_header[3] = (char)('0' + node->as.header.level);
|
139
|
+
cmark_strbuf_puts(html, end_header);
|
140
|
+
cmark_strbuf_puts(html, ">\n");
|
141
|
+
}
|
142
|
+
break;
|
143
|
+
|
144
|
+
case CMARK_NODE_CODE_BLOCK:
|
145
|
+
cr(html);
|
146
|
+
|
147
|
+
if (!node->as.code.fenced || node->as.code.info.len == 0) {
|
148
|
+
cmark_strbuf_puts(html, "<pre");
|
149
|
+
S_render_sourcepos(node, html, options);
|
150
|
+
cmark_strbuf_puts(html, "><code>");
|
151
|
+
} else {
|
152
|
+
bufsize_t first_tag = 0;
|
153
|
+
while (first_tag < node->as.code.info.len &&
|
154
|
+
!cmark_isspace(node->as.code.info.data[first_tag])) {
|
155
|
+
first_tag += 1;
|
156
|
+
}
|
157
|
+
|
158
|
+
cmark_strbuf_puts(html, "<pre");
|
159
|
+
S_render_sourcepos(node, html, options);
|
160
|
+
cmark_strbuf_puts(html, "><code class=\"language-");
|
161
|
+
escape_html(html, node->as.code.info.data, first_tag);
|
162
|
+
cmark_strbuf_puts(html, "\">");
|
163
|
+
}
|
164
|
+
|
165
|
+
escape_html(html, node->as.code.literal.data, node->as.code.literal.len);
|
166
|
+
cmark_strbuf_puts(html, "</code></pre>\n");
|
167
|
+
break;
|
168
|
+
|
169
|
+
case CMARK_NODE_HTML:
|
170
|
+
cr(html);
|
171
|
+
if (options & CMARK_OPT_SAFE) {
|
172
|
+
cmark_strbuf_puts(html, "<!-- raw HTML omitted -->");
|
173
|
+
} else {
|
174
|
+
cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
|
175
|
+
}
|
176
|
+
cr(html);
|
177
|
+
break;
|
178
|
+
|
179
|
+
case CMARK_NODE_HRULE:
|
180
|
+
cr(html);
|
181
|
+
cmark_strbuf_puts(html, "<hr");
|
182
|
+
S_render_sourcepos(node, html, options);
|
183
|
+
cmark_strbuf_puts(html, " />\n");
|
184
|
+
break;
|
185
|
+
|
186
|
+
case CMARK_NODE_PARAGRAPH:
|
187
|
+
parent = cmark_node_parent(node);
|
188
|
+
grandparent = cmark_node_parent(parent);
|
189
|
+
if (grandparent != NULL && grandparent->type == CMARK_NODE_LIST) {
|
190
|
+
tight = grandparent->as.list.tight;
|
191
|
+
} else {
|
192
|
+
tight = false;
|
193
|
+
}
|
194
|
+
if (!tight) {
|
195
|
+
if (entering) {
|
196
|
+
cr(html);
|
197
|
+
cmark_strbuf_puts(html, "<p");
|
198
|
+
S_render_sourcepos(node, html, options);
|
199
|
+
cmark_strbuf_putc(html, '>');
|
200
|
+
} else {
|
201
|
+
cmark_strbuf_puts(html, "</p>\n");
|
202
|
+
}
|
203
|
+
}
|
204
|
+
break;
|
205
|
+
|
206
|
+
case CMARK_NODE_TEXT:
|
207
|
+
escape_html(html, node->as.literal.data, node->as.literal.len);
|
208
|
+
break;
|
209
|
+
|
210
|
+
case CMARK_NODE_LINEBREAK:
|
211
|
+
cmark_strbuf_puts(html, "<br />\n");
|
212
|
+
break;
|
213
|
+
|
214
|
+
case CMARK_NODE_SOFTBREAK:
|
215
|
+
if (options & CMARK_OPT_HARDBREAKS) {
|
216
|
+
cmark_strbuf_puts(html, "<br />\n");
|
217
|
+
} else {
|
218
|
+
cmark_strbuf_putc(html, '\n');
|
219
|
+
}
|
220
|
+
break;
|
221
|
+
|
222
|
+
case CMARK_NODE_CODE:
|
223
|
+
cmark_strbuf_puts(html, "<code>");
|
224
|
+
escape_html(html, node->as.literal.data, node->as.literal.len);
|
225
|
+
cmark_strbuf_puts(html, "</code>");
|
226
|
+
break;
|
227
|
+
|
228
|
+
case CMARK_NODE_INLINE_HTML:
|
229
|
+
if (options & CMARK_OPT_SAFE) {
|
230
|
+
cmark_strbuf_puts(html, "<!-- raw HTML omitted -->");
|
231
|
+
} else {
|
232
|
+
cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
|
233
|
+
}
|
234
|
+
break;
|
235
|
+
|
236
|
+
case CMARK_NODE_STRONG:
|
237
|
+
if (entering) {
|
238
|
+
cmark_strbuf_puts(html, "<strong>");
|
239
|
+
} else {
|
240
|
+
cmark_strbuf_puts(html, "</strong>");
|
241
|
+
}
|
242
|
+
break;
|
243
|
+
|
244
|
+
case CMARK_NODE_EMPH:
|
245
|
+
if (entering) {
|
246
|
+
cmark_strbuf_puts(html, "<em>");
|
247
|
+
} else {
|
248
|
+
cmark_strbuf_puts(html, "</em>");
|
249
|
+
}
|
250
|
+
break;
|
251
|
+
|
252
|
+
case CMARK_NODE_LINK:
|
253
|
+
if (entering) {
|
254
|
+
cmark_strbuf_puts(html, "<a href=\"");
|
255
|
+
if (!((options & CMARK_OPT_SAFE) &&
|
256
|
+
scan_dangerous_url(&node->as.link.url, 0))) {
|
257
|
+
houdini_escape_href(html, node->as.link.url.data,
|
258
|
+
node->as.link.url.len);
|
259
|
+
}
|
260
|
+
if (node->as.link.title.len) {
|
261
|
+
cmark_strbuf_puts(html, "\" title=\"");
|
262
|
+
escape_html(html, node->as.link.title.data, node->as.link.title.len);
|
263
|
+
}
|
264
|
+
cmark_strbuf_puts(html, "\">");
|
265
|
+
} else {
|
266
|
+
cmark_strbuf_puts(html, "</a>");
|
267
|
+
}
|
268
|
+
break;
|
269
|
+
|
270
|
+
case CMARK_NODE_IMAGE:
|
271
|
+
if (entering) {
|
272
|
+
cmark_strbuf_puts(html, "<img src=\"");
|
273
|
+
if (!((options & CMARK_OPT_SAFE) &&
|
274
|
+
scan_dangerous_url(&node->as.link.url, 0))) {
|
275
|
+
houdini_escape_href(html, node->as.link.url.data,
|
276
|
+
node->as.link.url.len);
|
277
|
+
}
|
278
|
+
cmark_strbuf_puts(html, "\" alt=\"");
|
279
|
+
state->plain = node;
|
280
|
+
} else {
|
281
|
+
if (node->as.link.title.len) {
|
282
|
+
cmark_strbuf_puts(html, "\" title=\"");
|
283
|
+
escape_html(html, node->as.link.title.data, node->as.link.title.len);
|
284
|
+
}
|
285
|
+
|
286
|
+
cmark_strbuf_puts(html, "\" />");
|
287
|
+
}
|
288
|
+
break;
|
289
|
+
|
290
|
+
default:
|
291
|
+
assert(false);
|
292
|
+
break;
|
293
|
+
}
|
294
|
+
|
295
|
+
// cmark_strbuf_putc(html, 'x');
|
296
|
+
return 1;
|
314
297
|
}
|
315
298
|
|
316
|
-
char *cmark_render_html(cmark_node *root, int options)
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
return result;
|
299
|
+
char *cmark_render_html(cmark_node *root, int options) {
|
300
|
+
char *result;
|
301
|
+
cmark_strbuf html = GH_BUF_INIT;
|
302
|
+
cmark_event_type ev_type;
|
303
|
+
cmark_node *cur;
|
304
|
+
struct render_state state = {&html, NULL};
|
305
|
+
cmark_iter *iter = cmark_iter_new(root);
|
306
|
+
|
307
|
+
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
|
308
|
+
cur = cmark_iter_get_node(iter);
|
309
|
+
S_render_node(cur, ev_type, &state, options);
|
310
|
+
}
|
311
|
+
result = (char *)cmark_strbuf_detach(&html);
|
312
|
+
|
313
|
+
cmark_iter_free(iter);
|
314
|
+
return result;
|
333
315
|
}
|