commonmarker 0.23.10 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +1220 -0
- data/Cargo.toml +7 -0
- data/README.md +217 -170
- data/ext/commonmarker/Cargo.toml +20 -0
- data/ext/commonmarker/extconf.rb +3 -6
- data/ext/commonmarker/src/lib.rs +183 -0
- data/ext/commonmarker/src/node.rs +1112 -0
- data/ext/commonmarker/src/options.rs +165 -0
- data/ext/commonmarker/src/plugins/syntax_highlighting.rs +74 -0
- data/ext/commonmarker/src/plugins.rs +3 -0
- data/ext/commonmarker/src/utils.rs +8 -0
- data/lib/commonmarker/config.rb +90 -40
- data/lib/commonmarker/constants.rb +7 -0
- data/lib/commonmarker/extension.rb +14 -0
- data/lib/commonmarker/node/ast.rb +8 -0
- data/lib/commonmarker/node/inspect.rb +14 -4
- data/lib/commonmarker/node.rb +29 -47
- data/lib/commonmarker/renderer.rb +1 -127
- data/lib/commonmarker/utils.rb +22 -0
- data/lib/commonmarker/version.rb +2 -2
- data/lib/commonmarker.rb +27 -25
- metadata +38 -186
- data/Rakefile +0 -109
- data/bin/commonmarker +0 -118
- data/commonmarker.gemspec +0 -38
- data/ext/commonmarker/arena.c +0 -104
- data/ext/commonmarker/autolink.c +0 -508
- data/ext/commonmarker/autolink.h +0 -8
- data/ext/commonmarker/blocks.c +0 -1622
- data/ext/commonmarker/buffer.c +0 -278
- data/ext/commonmarker/buffer.h +0 -116
- data/ext/commonmarker/case_fold_switch.inc +0 -4327
- data/ext/commonmarker/chunk.h +0 -135
- data/ext/commonmarker/cmark-gfm-core-extensions.h +0 -54
- data/ext/commonmarker/cmark-gfm-extension_api.h +0 -737
- data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
- data/ext/commonmarker/cmark-gfm.h +0 -833
- data/ext/commonmarker/cmark-gfm_export.h +0 -42
- data/ext/commonmarker/cmark-gfm_version.h +0 -7
- data/ext/commonmarker/cmark.c +0 -55
- data/ext/commonmarker/cmark_ctype.c +0 -44
- data/ext/commonmarker/cmark_ctype.h +0 -33
- data/ext/commonmarker/commonmark.c +0 -514
- data/ext/commonmarker/commonmarker.c +0 -1308
- data/ext/commonmarker/commonmarker.h +0 -16
- data/ext/commonmarker/config.h +0 -76
- data/ext/commonmarker/core-extensions.c +0 -27
- data/ext/commonmarker/entities.inc +0 -2138
- data/ext/commonmarker/ext_scanners.c +0 -879
- data/ext/commonmarker/ext_scanners.h +0 -24
- data/ext/commonmarker/footnotes.c +0 -63
- data/ext/commonmarker/footnotes.h +0 -27
- data/ext/commonmarker/houdini.h +0 -57
- data/ext/commonmarker/houdini_href_e.c +0 -100
- data/ext/commonmarker/houdini_html_e.c +0 -66
- data/ext/commonmarker/houdini_html_u.c +0 -149
- data/ext/commonmarker/html.c +0 -502
- data/ext/commonmarker/html.h +0 -27
- data/ext/commonmarker/inlines.c +0 -1788
- data/ext/commonmarker/inlines.h +0 -29
- data/ext/commonmarker/iterator.c +0 -159
- data/ext/commonmarker/iterator.h +0 -26
- data/ext/commonmarker/latex.c +0 -468
- data/ext/commonmarker/linked_list.c +0 -37
- data/ext/commonmarker/man.c +0 -274
- data/ext/commonmarker/map.c +0 -129
- data/ext/commonmarker/map.h +0 -44
- data/ext/commonmarker/node.c +0 -1045
- data/ext/commonmarker/node.h +0 -167
- data/ext/commonmarker/parser.h +0 -59
- data/ext/commonmarker/plaintext.c +0 -218
- data/ext/commonmarker/plugin.c +0 -36
- data/ext/commonmarker/plugin.h +0 -34
- data/ext/commonmarker/references.c +0 -43
- data/ext/commonmarker/references.h +0 -26
- data/ext/commonmarker/registry.c +0 -63
- data/ext/commonmarker/registry.h +0 -24
- data/ext/commonmarker/render.c +0 -213
- data/ext/commonmarker/render.h +0 -62
- data/ext/commonmarker/scanners.c +0 -14056
- data/ext/commonmarker/scanners.h +0 -70
- data/ext/commonmarker/scanners.re +0 -341
- data/ext/commonmarker/strikethrough.c +0 -167
- data/ext/commonmarker/strikethrough.h +0 -9
- data/ext/commonmarker/syntax_extension.c +0 -149
- data/ext/commonmarker/syntax_extension.h +0 -34
- data/ext/commonmarker/table.c +0 -917
- data/ext/commonmarker/table.h +0 -12
- data/ext/commonmarker/tagfilter.c +0 -60
- data/ext/commonmarker/tagfilter.h +0 -8
- data/ext/commonmarker/tasklist.c +0 -156
- data/ext/commonmarker/tasklist.h +0 -8
- data/ext/commonmarker/utf8.c +0 -317
- data/ext/commonmarker/utf8.h +0 -35
- data/ext/commonmarker/xml.c +0 -182
- data/lib/commonmarker/renderer/html_renderer.rb +0 -256
data/ext/commonmarker/html.c
DELETED
@@ -1,502 +0,0 @@
|
|
1
|
-
#include <stdlib.h>
|
2
|
-
#include <stdio.h>
|
3
|
-
#include <string.h>
|
4
|
-
#include <assert.h>
|
5
|
-
#include "cmark_ctype.h"
|
6
|
-
#include "config.h"
|
7
|
-
#include "cmark-gfm.h"
|
8
|
-
#include "houdini.h"
|
9
|
-
#include "scanners.h"
|
10
|
-
#include "syntax_extension.h"
|
11
|
-
#include "html.h"
|
12
|
-
#include "render.h"
|
13
|
-
|
14
|
-
// Functions to convert cmark_nodes to HTML strings.
|
15
|
-
|
16
|
-
static void escape_html(cmark_strbuf *dest, const unsigned char *source,
|
17
|
-
bufsize_t length) {
|
18
|
-
houdini_escape_html0(dest, source, length, 0);
|
19
|
-
}
|
20
|
-
|
21
|
-
static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size_t len) {
|
22
|
-
cmark_strbuf *html = renderer->html;
|
23
|
-
cmark_llist *it;
|
24
|
-
cmark_syntax_extension *ext;
|
25
|
-
bool filtered;
|
26
|
-
uint8_t *match;
|
27
|
-
|
28
|
-
while (len) {
|
29
|
-
match = (uint8_t *) memchr(data, '<', len);
|
30
|
-
if (!match)
|
31
|
-
break;
|
32
|
-
|
33
|
-
if (match != data) {
|
34
|
-
cmark_strbuf_put(html, data, (bufsize_t)(match - data));
|
35
|
-
len -= (match - data);
|
36
|
-
data = match;
|
37
|
-
}
|
38
|
-
|
39
|
-
filtered = false;
|
40
|
-
for (it = renderer->filter_extensions; it; it = it->next) {
|
41
|
-
ext = ((cmark_syntax_extension *) it->data);
|
42
|
-
if (!ext->html_filter_func(ext, data, len)) {
|
43
|
-
filtered = true;
|
44
|
-
break;
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
if (!filtered) {
|
49
|
-
cmark_strbuf_putc(html, '<');
|
50
|
-
} else {
|
51
|
-
cmark_strbuf_puts(html, "<");
|
52
|
-
}
|
53
|
-
|
54
|
-
++data;
|
55
|
-
--len;
|
56
|
-
}
|
57
|
-
|
58
|
-
if (len)
|
59
|
-
cmark_strbuf_put(html, data, (bufsize_t)len);
|
60
|
-
}
|
61
|
-
|
62
|
-
static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *html, cmark_node *node) {
|
63
|
-
if (renderer->written_footnote_ix >= renderer->footnote_ix)
|
64
|
-
return false;
|
65
|
-
renderer->written_footnote_ix = renderer->footnote_ix;
|
66
|
-
char m[32];
|
67
|
-
snprintf(m, sizeof(m), "%d", renderer->written_footnote_ix);
|
68
|
-
|
69
|
-
cmark_strbuf_puts(html, "<a href=\"#fnref-");
|
70
|
-
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
|
71
|
-
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"");
|
72
|
-
cmark_strbuf_puts(html, m);
|
73
|
-
cmark_strbuf_puts(html, "\" aria-label=\"Back to reference ");
|
74
|
-
cmark_strbuf_puts(html, m);
|
75
|
-
cmark_strbuf_puts(html, "\">↩</a>");
|
76
|
-
|
77
|
-
if (node->footnote.def_count > 1)
|
78
|
-
{
|
79
|
-
for(int i = 2; i <= node->footnote.def_count; i++) {
|
80
|
-
char n[32];
|
81
|
-
snprintf(n, sizeof(n), "%d", i);
|
82
|
-
|
83
|
-
cmark_strbuf_puts(html, " <a href=\"#fnref-");
|
84
|
-
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
|
85
|
-
cmark_strbuf_puts(html, "-");
|
86
|
-
cmark_strbuf_puts(html, n);
|
87
|
-
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"");
|
88
|
-
cmark_strbuf_puts(html, m);
|
89
|
-
cmark_strbuf_puts(html, "-");
|
90
|
-
cmark_strbuf_puts(html, n);
|
91
|
-
cmark_strbuf_puts(html, "\" aria-label=\"Back to reference ");
|
92
|
-
cmark_strbuf_puts(html, m);
|
93
|
-
cmark_strbuf_puts(html, "-");
|
94
|
-
cmark_strbuf_puts(html, n);
|
95
|
-
cmark_strbuf_puts(html, "\">↩<sup class=\"footnote-ref\">");
|
96
|
-
cmark_strbuf_puts(html, n);
|
97
|
-
cmark_strbuf_puts(html, "</sup></a>");
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
return true;
|
102
|
-
}
|
103
|
-
|
104
|
-
static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
|
105
|
-
cmark_event_type ev_type, int options) {
|
106
|
-
cmark_node *parent;
|
107
|
-
cmark_node *grandparent;
|
108
|
-
cmark_strbuf *html = renderer->html;
|
109
|
-
cmark_llist *it;
|
110
|
-
cmark_syntax_extension *ext;
|
111
|
-
char start_heading[] = "<h0";
|
112
|
-
char end_heading[] = "</h0";
|
113
|
-
bool tight;
|
114
|
-
bool filtered;
|
115
|
-
char buffer[BUFFER_SIZE];
|
116
|
-
|
117
|
-
bool entering = (ev_type == CMARK_EVENT_ENTER);
|
118
|
-
|
119
|
-
if (renderer->plain == node) { // back at original node
|
120
|
-
renderer->plain = NULL;
|
121
|
-
}
|
122
|
-
|
123
|
-
if (renderer->plain != NULL) {
|
124
|
-
switch (node->type) {
|
125
|
-
case CMARK_NODE_TEXT:
|
126
|
-
case CMARK_NODE_CODE:
|
127
|
-
case CMARK_NODE_HTML_INLINE:
|
128
|
-
escape_html(html, node->as.literal.data, node->as.literal.len);
|
129
|
-
break;
|
130
|
-
|
131
|
-
case CMARK_NODE_LINEBREAK:
|
132
|
-
case CMARK_NODE_SOFTBREAK:
|
133
|
-
cmark_strbuf_putc(html, ' ');
|
134
|
-
break;
|
135
|
-
|
136
|
-
default:
|
137
|
-
break;
|
138
|
-
}
|
139
|
-
return 1;
|
140
|
-
}
|
141
|
-
|
142
|
-
if (node->extension && node->extension->html_render_func) {
|
143
|
-
node->extension->html_render_func(node->extension, renderer, node, ev_type, options);
|
144
|
-
return 1;
|
145
|
-
}
|
146
|
-
|
147
|
-
switch (node->type) {
|
148
|
-
case CMARK_NODE_DOCUMENT:
|
149
|
-
break;
|
150
|
-
|
151
|
-
case CMARK_NODE_BLOCK_QUOTE:
|
152
|
-
if (entering) {
|
153
|
-
cmark_html_render_cr(html);
|
154
|
-
cmark_strbuf_puts(html, "<blockquote");
|
155
|
-
cmark_html_render_sourcepos(node, html, options);
|
156
|
-
cmark_strbuf_puts(html, ">\n");
|
157
|
-
} else {
|
158
|
-
cmark_html_render_cr(html);
|
159
|
-
cmark_strbuf_puts(html, "</blockquote>\n");
|
160
|
-
}
|
161
|
-
break;
|
162
|
-
|
163
|
-
case CMARK_NODE_LIST: {
|
164
|
-
cmark_list_type list_type = node->as.list.list_type;
|
165
|
-
int start = node->as.list.start;
|
166
|
-
|
167
|
-
if (entering) {
|
168
|
-
cmark_html_render_cr(html);
|
169
|
-
if (list_type == CMARK_BULLET_LIST) {
|
170
|
-
cmark_strbuf_puts(html, "<ul");
|
171
|
-
cmark_html_render_sourcepos(node, html, options);
|
172
|
-
cmark_strbuf_puts(html, ">\n");
|
173
|
-
} else if (start == 1) {
|
174
|
-
cmark_strbuf_puts(html, "<ol");
|
175
|
-
cmark_html_render_sourcepos(node, html, options);
|
176
|
-
cmark_strbuf_puts(html, ">\n");
|
177
|
-
} else {
|
178
|
-
snprintf(buffer, BUFFER_SIZE, "<ol start=\"%d\"", start);
|
179
|
-
cmark_strbuf_puts(html, buffer);
|
180
|
-
cmark_html_render_sourcepos(node, html, options);
|
181
|
-
cmark_strbuf_puts(html, ">\n");
|
182
|
-
}
|
183
|
-
} else {
|
184
|
-
cmark_strbuf_puts(html,
|
185
|
-
list_type == CMARK_BULLET_LIST ? "</ul>\n" : "</ol>\n");
|
186
|
-
}
|
187
|
-
break;
|
188
|
-
}
|
189
|
-
|
190
|
-
case CMARK_NODE_ITEM:
|
191
|
-
if (entering) {
|
192
|
-
cmark_html_render_cr(html);
|
193
|
-
cmark_strbuf_puts(html, "<li");
|
194
|
-
cmark_html_render_sourcepos(node, html, options);
|
195
|
-
cmark_strbuf_putc(html, '>');
|
196
|
-
} else {
|
197
|
-
cmark_strbuf_puts(html, "</li>\n");
|
198
|
-
}
|
199
|
-
break;
|
200
|
-
|
201
|
-
case CMARK_NODE_HEADING:
|
202
|
-
if (entering) {
|
203
|
-
cmark_html_render_cr(html);
|
204
|
-
start_heading[2] = (char)('0' + node->as.heading.level);
|
205
|
-
cmark_strbuf_puts(html, start_heading);
|
206
|
-
cmark_html_render_sourcepos(node, html, options);
|
207
|
-
cmark_strbuf_putc(html, '>');
|
208
|
-
} else {
|
209
|
-
end_heading[3] = (char)('0' + node->as.heading.level);
|
210
|
-
cmark_strbuf_puts(html, end_heading);
|
211
|
-
cmark_strbuf_puts(html, ">\n");
|
212
|
-
}
|
213
|
-
break;
|
214
|
-
|
215
|
-
case CMARK_NODE_CODE_BLOCK:
|
216
|
-
cmark_html_render_cr(html);
|
217
|
-
|
218
|
-
if (node->as.code.info.len == 0) {
|
219
|
-
cmark_strbuf_puts(html, "<pre");
|
220
|
-
cmark_html_render_sourcepos(node, html, options);
|
221
|
-
cmark_strbuf_puts(html, "><code>");
|
222
|
-
} else {
|
223
|
-
bufsize_t first_tag = 0;
|
224
|
-
while (first_tag < node->as.code.info.len &&
|
225
|
-
!cmark_isspace(node->as.code.info.data[first_tag])) {
|
226
|
-
first_tag += 1;
|
227
|
-
}
|
228
|
-
|
229
|
-
if (options & CMARK_OPT_GITHUB_PRE_LANG) {
|
230
|
-
cmark_strbuf_puts(html, "<pre");
|
231
|
-
cmark_html_render_sourcepos(node, html, options);
|
232
|
-
cmark_strbuf_puts(html, " lang=\"");
|
233
|
-
escape_html(html, node->as.code.info.data, first_tag);
|
234
|
-
if (first_tag < node->as.code.info.len && (options & CMARK_OPT_FULL_INFO_STRING)) {
|
235
|
-
cmark_strbuf_puts(html, "\" data-meta=\"");
|
236
|
-
escape_html(html, node->as.code.info.data + first_tag + 1, node->as.code.info.len - first_tag - 1);
|
237
|
-
}
|
238
|
-
cmark_strbuf_puts(html, "\"><code>");
|
239
|
-
} else {
|
240
|
-
cmark_strbuf_puts(html, "<pre");
|
241
|
-
cmark_html_render_sourcepos(node, html, options);
|
242
|
-
cmark_strbuf_puts(html, "><code class=\"language-");
|
243
|
-
escape_html(html, node->as.code.info.data, first_tag);
|
244
|
-
if (first_tag < node->as.code.info.len && (options & CMARK_OPT_FULL_INFO_STRING)) {
|
245
|
-
cmark_strbuf_puts(html, "\" data-meta=\"");
|
246
|
-
escape_html(html, node->as.code.info.data + first_tag + 1, node->as.code.info.len - first_tag - 1);
|
247
|
-
}
|
248
|
-
cmark_strbuf_puts(html, "\">");
|
249
|
-
}
|
250
|
-
}
|
251
|
-
|
252
|
-
escape_html(html, node->as.code.literal.data, node->as.code.literal.len);
|
253
|
-
cmark_strbuf_puts(html, "</code></pre>\n");
|
254
|
-
break;
|
255
|
-
|
256
|
-
case CMARK_NODE_HTML_BLOCK:
|
257
|
-
cmark_html_render_cr(html);
|
258
|
-
if (!(options & CMARK_OPT_UNSAFE)) {
|
259
|
-
cmark_strbuf_puts(html, "<!-- raw HTML omitted -->");
|
260
|
-
} else if (renderer->filter_extensions) {
|
261
|
-
filter_html_block(renderer, node->as.literal.data, node->as.literal.len);
|
262
|
-
} else {
|
263
|
-
cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
|
264
|
-
}
|
265
|
-
cmark_html_render_cr(html);
|
266
|
-
break;
|
267
|
-
|
268
|
-
case CMARK_NODE_CUSTOM_BLOCK:
|
269
|
-
cmark_html_render_cr(html);
|
270
|
-
if (entering) {
|
271
|
-
cmark_strbuf_put(html, node->as.custom.on_enter.data,
|
272
|
-
node->as.custom.on_enter.len);
|
273
|
-
} else {
|
274
|
-
cmark_strbuf_put(html, node->as.custom.on_exit.data,
|
275
|
-
node->as.custom.on_exit.len);
|
276
|
-
}
|
277
|
-
cmark_html_render_cr(html);
|
278
|
-
break;
|
279
|
-
|
280
|
-
case CMARK_NODE_THEMATIC_BREAK:
|
281
|
-
cmark_html_render_cr(html);
|
282
|
-
cmark_strbuf_puts(html, "<hr");
|
283
|
-
cmark_html_render_sourcepos(node, html, options);
|
284
|
-
cmark_strbuf_puts(html, " />\n");
|
285
|
-
break;
|
286
|
-
|
287
|
-
case CMARK_NODE_PARAGRAPH:
|
288
|
-
parent = cmark_node_parent(node);
|
289
|
-
grandparent = cmark_node_parent(parent);
|
290
|
-
if (grandparent != NULL && grandparent->type == CMARK_NODE_LIST) {
|
291
|
-
tight = grandparent->as.list.tight;
|
292
|
-
} else {
|
293
|
-
tight = false;
|
294
|
-
}
|
295
|
-
if (!tight) {
|
296
|
-
if (entering) {
|
297
|
-
cmark_html_render_cr(html);
|
298
|
-
cmark_strbuf_puts(html, "<p");
|
299
|
-
cmark_html_render_sourcepos(node, html, options);
|
300
|
-
cmark_strbuf_putc(html, '>');
|
301
|
-
} else {
|
302
|
-
if (parent->type == CMARK_NODE_FOOTNOTE_DEFINITION && node->next == NULL) {
|
303
|
-
cmark_strbuf_putc(html, ' ');
|
304
|
-
S_put_footnote_backref(renderer, html, parent);
|
305
|
-
}
|
306
|
-
cmark_strbuf_puts(html, "</p>\n");
|
307
|
-
}
|
308
|
-
}
|
309
|
-
break;
|
310
|
-
|
311
|
-
case CMARK_NODE_TEXT:
|
312
|
-
escape_html(html, node->as.literal.data, node->as.literal.len);
|
313
|
-
break;
|
314
|
-
|
315
|
-
case CMARK_NODE_LINEBREAK:
|
316
|
-
cmark_strbuf_puts(html, "<br />\n");
|
317
|
-
break;
|
318
|
-
|
319
|
-
case CMARK_NODE_SOFTBREAK:
|
320
|
-
if (options & CMARK_OPT_HARDBREAKS) {
|
321
|
-
cmark_strbuf_puts(html, "<br />\n");
|
322
|
-
} else if (options & CMARK_OPT_NOBREAKS) {
|
323
|
-
cmark_strbuf_putc(html, ' ');
|
324
|
-
} else {
|
325
|
-
cmark_strbuf_putc(html, '\n');
|
326
|
-
}
|
327
|
-
break;
|
328
|
-
|
329
|
-
case CMARK_NODE_CODE:
|
330
|
-
cmark_strbuf_puts(html, "<code>");
|
331
|
-
escape_html(html, node->as.literal.data, node->as.literal.len);
|
332
|
-
cmark_strbuf_puts(html, "</code>");
|
333
|
-
break;
|
334
|
-
|
335
|
-
case CMARK_NODE_HTML_INLINE:
|
336
|
-
if (!(options & CMARK_OPT_UNSAFE)) {
|
337
|
-
cmark_strbuf_puts(html, "<!-- raw HTML omitted -->");
|
338
|
-
} else {
|
339
|
-
filtered = false;
|
340
|
-
for (it = renderer->filter_extensions; it; it = it->next) {
|
341
|
-
ext = (cmark_syntax_extension *) it->data;
|
342
|
-
if (!ext->html_filter_func(ext, node->as.literal.data, node->as.literal.len)) {
|
343
|
-
filtered = true;
|
344
|
-
break;
|
345
|
-
}
|
346
|
-
}
|
347
|
-
if (!filtered) {
|
348
|
-
cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
|
349
|
-
} else {
|
350
|
-
cmark_strbuf_puts(html, "<");
|
351
|
-
cmark_strbuf_put(html, node->as.literal.data + 1, node->as.literal.len - 1);
|
352
|
-
}
|
353
|
-
}
|
354
|
-
break;
|
355
|
-
|
356
|
-
case CMARK_NODE_CUSTOM_INLINE:
|
357
|
-
if (entering) {
|
358
|
-
cmark_strbuf_put(html, node->as.custom.on_enter.data,
|
359
|
-
node->as.custom.on_enter.len);
|
360
|
-
} else {
|
361
|
-
cmark_strbuf_put(html, node->as.custom.on_exit.data,
|
362
|
-
node->as.custom.on_exit.len);
|
363
|
-
}
|
364
|
-
break;
|
365
|
-
|
366
|
-
case CMARK_NODE_STRONG:
|
367
|
-
if (node->parent == NULL || node->parent->type != CMARK_NODE_STRONG) {
|
368
|
-
if (entering) {
|
369
|
-
cmark_strbuf_puts(html, "<strong>");
|
370
|
-
} else {
|
371
|
-
cmark_strbuf_puts(html, "</strong>");
|
372
|
-
}
|
373
|
-
}
|
374
|
-
break;
|
375
|
-
|
376
|
-
case CMARK_NODE_EMPH:
|
377
|
-
if (entering) {
|
378
|
-
cmark_strbuf_puts(html, "<em>");
|
379
|
-
} else {
|
380
|
-
cmark_strbuf_puts(html, "</em>");
|
381
|
-
}
|
382
|
-
break;
|
383
|
-
|
384
|
-
case CMARK_NODE_LINK:
|
385
|
-
if (entering) {
|
386
|
-
cmark_strbuf_puts(html, "<a href=\"");
|
387
|
-
if ((options & CMARK_OPT_UNSAFE) ||
|
388
|
-
!(scan_dangerous_url(&node->as.link.url, 0))) {
|
389
|
-
houdini_escape_href(html, node->as.link.url.data,
|
390
|
-
node->as.link.url.len);
|
391
|
-
}
|
392
|
-
if (node->as.link.title.len) {
|
393
|
-
cmark_strbuf_puts(html, "\" title=\"");
|
394
|
-
escape_html(html, node->as.link.title.data, node->as.link.title.len);
|
395
|
-
}
|
396
|
-
cmark_strbuf_puts(html, "\">");
|
397
|
-
} else {
|
398
|
-
cmark_strbuf_puts(html, "</a>");
|
399
|
-
}
|
400
|
-
break;
|
401
|
-
|
402
|
-
case CMARK_NODE_IMAGE:
|
403
|
-
if (entering) {
|
404
|
-
cmark_strbuf_puts(html, "<img src=\"");
|
405
|
-
if ((options & CMARK_OPT_UNSAFE) ||
|
406
|
-
!(scan_dangerous_url(&node->as.link.url, 0))) {
|
407
|
-
houdini_escape_href(html, node->as.link.url.data,
|
408
|
-
node->as.link.url.len);
|
409
|
-
}
|
410
|
-
cmark_strbuf_puts(html, "\" alt=\"");
|
411
|
-
renderer->plain = node;
|
412
|
-
} else {
|
413
|
-
if (node->as.link.title.len) {
|
414
|
-
cmark_strbuf_puts(html, "\" title=\"");
|
415
|
-
escape_html(html, node->as.link.title.data, node->as.link.title.len);
|
416
|
-
}
|
417
|
-
|
418
|
-
cmark_strbuf_puts(html, "\" />");
|
419
|
-
}
|
420
|
-
break;
|
421
|
-
|
422
|
-
case CMARK_NODE_FOOTNOTE_DEFINITION:
|
423
|
-
if (entering) {
|
424
|
-
if (renderer->footnote_ix == 0) {
|
425
|
-
cmark_strbuf_puts(html, "<section class=\"footnotes\" data-footnotes>\n<ol>\n");
|
426
|
-
}
|
427
|
-
++renderer->footnote_ix;
|
428
|
-
|
429
|
-
cmark_strbuf_puts(html, "<li id=\"fn-");
|
430
|
-
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
|
431
|
-
cmark_strbuf_puts(html, "\">\n");
|
432
|
-
} else {
|
433
|
-
if (S_put_footnote_backref(renderer, html, node)) {
|
434
|
-
cmark_strbuf_putc(html, '\n');
|
435
|
-
}
|
436
|
-
cmark_strbuf_puts(html, "</li>\n");
|
437
|
-
}
|
438
|
-
break;
|
439
|
-
|
440
|
-
case CMARK_NODE_FOOTNOTE_REFERENCE:
|
441
|
-
if (entering) {
|
442
|
-
cmark_strbuf_puts(html, "<sup class=\"footnote-ref\"><a href=\"#fn-");
|
443
|
-
houdini_escape_href(html, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len);
|
444
|
-
cmark_strbuf_puts(html, "\" id=\"fnref-");
|
445
|
-
houdini_escape_href(html, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len);
|
446
|
-
|
447
|
-
if (node->footnote.ref_ix > 1) {
|
448
|
-
char n[32];
|
449
|
-
snprintf(n, sizeof(n), "%d", node->footnote.ref_ix);
|
450
|
-
cmark_strbuf_puts(html, "-");
|
451
|
-
cmark_strbuf_puts(html, n);
|
452
|
-
}
|
453
|
-
|
454
|
-
cmark_strbuf_puts(html, "\" data-footnote-ref>");
|
455
|
-
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
|
456
|
-
cmark_strbuf_puts(html, "</a></sup>");
|
457
|
-
}
|
458
|
-
break;
|
459
|
-
|
460
|
-
default:
|
461
|
-
assert(false);
|
462
|
-
break;
|
463
|
-
}
|
464
|
-
|
465
|
-
return 1;
|
466
|
-
}
|
467
|
-
|
468
|
-
char *cmark_render_html(cmark_node *root, int options, cmark_llist *extensions) {
|
469
|
-
return cmark_render_html_with_mem(root, options, extensions, cmark_node_mem(root));
|
470
|
-
}
|
471
|
-
|
472
|
-
char *cmark_render_html_with_mem(cmark_node *root, int options, cmark_llist *extensions, cmark_mem *mem) {
|
473
|
-
char *result;
|
474
|
-
cmark_strbuf html = CMARK_BUF_INIT(mem);
|
475
|
-
cmark_event_type ev_type;
|
476
|
-
cmark_node *cur;
|
477
|
-
cmark_html_renderer renderer = {&html, NULL, NULL, 0, 0, NULL};
|
478
|
-
cmark_iter *iter = cmark_iter_new(root);
|
479
|
-
|
480
|
-
for (; extensions; extensions = extensions->next)
|
481
|
-
if (((cmark_syntax_extension *) extensions->data)->html_filter_func)
|
482
|
-
renderer.filter_extensions = cmark_llist_append(
|
483
|
-
mem,
|
484
|
-
renderer.filter_extensions,
|
485
|
-
(cmark_syntax_extension *) extensions->data);
|
486
|
-
|
487
|
-
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
|
488
|
-
cur = cmark_iter_get_node(iter);
|
489
|
-
S_render_node(&renderer, cur, ev_type, options);
|
490
|
-
}
|
491
|
-
|
492
|
-
if (renderer.footnote_ix) {
|
493
|
-
cmark_strbuf_puts(&html, "</ol>\n</section>\n");
|
494
|
-
}
|
495
|
-
|
496
|
-
result = (char *)cmark_strbuf_detach(&html);
|
497
|
-
|
498
|
-
cmark_llist_free(mem, renderer.filter_extensions);
|
499
|
-
|
500
|
-
cmark_iter_free(iter);
|
501
|
-
return result;
|
502
|
-
}
|
data/ext/commonmarker/html.h
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#ifndef CMARK_HTML_H
|
2
|
-
#define CMARK_HTML_H
|
3
|
-
|
4
|
-
#include "buffer.h"
|
5
|
-
#include "node.h"
|
6
|
-
|
7
|
-
CMARK_INLINE
|
8
|
-
static void cmark_html_render_cr(cmark_strbuf *html) {
|
9
|
-
if (html->size && html->ptr[html->size - 1] != '\n')
|
10
|
-
cmark_strbuf_putc(html, '\n');
|
11
|
-
}
|
12
|
-
|
13
|
-
#define BUFFER_SIZE 100
|
14
|
-
|
15
|
-
CMARK_INLINE
|
16
|
-
static void cmark_html_render_sourcepos(cmark_node *node, cmark_strbuf *html, int options) {
|
17
|
-
char buffer[BUFFER_SIZE];
|
18
|
-
if (CMARK_OPT_SOURCEPOS & options) {
|
19
|
-
snprintf(buffer, BUFFER_SIZE, " data-sourcepos=\"%d:%d-%d:%d\"",
|
20
|
-
cmark_node_get_start_line(node), cmark_node_get_start_column(node),
|
21
|
-
cmark_node_get_end_line(node), cmark_node_get_end_column(node));
|
22
|
-
cmark_strbuf_puts(html, buffer);
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
|
27
|
-
#endif
|