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
@@ -18,413 +18,391 @@
|
|
18
18
|
#define CR() renderer->cr(renderer)
|
19
19
|
#define BLANKLINE() renderer->blankline(renderer)
|
20
20
|
|
21
|
-
static inline void outc(cmark_renderer *renderer,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
default:
|
144
|
-
cmark_render_code_point(renderer, c);
|
145
|
-
}
|
21
|
+
static inline void outc(cmark_renderer *renderer, cmark_escaping escape,
|
22
|
+
int32_t c, unsigned char nextc) {
|
23
|
+
if (escape == LITERAL) {
|
24
|
+
cmark_render_code_point(renderer, c);
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
|
28
|
+
switch (c) {
|
29
|
+
case 123: // '{'
|
30
|
+
case 125: // '}'
|
31
|
+
case 35: // '#'
|
32
|
+
case 37: // '%'
|
33
|
+
case 38: // '&'
|
34
|
+
cmark_render_ascii(renderer, "\\");
|
35
|
+
cmark_render_code_point(renderer, c);
|
36
|
+
break;
|
37
|
+
case 36: // '$'
|
38
|
+
case 95: // '_'
|
39
|
+
if (escape == NORMAL) {
|
40
|
+
cmark_render_ascii(renderer, "\\");
|
41
|
+
}
|
42
|
+
cmark_render_code_point(renderer, c);
|
43
|
+
break;
|
44
|
+
case 45: // '-'
|
45
|
+
if (nextc == 45) { // prevent ligature
|
46
|
+
cmark_render_ascii(renderer, "\\-");
|
47
|
+
} else {
|
48
|
+
cmark_render_ascii(renderer, "-");
|
49
|
+
}
|
50
|
+
break;
|
51
|
+
case 126: // '~'
|
52
|
+
if (escape == NORMAL) {
|
53
|
+
cmark_render_ascii(renderer, "\\textasciitilde{}");
|
54
|
+
} else {
|
55
|
+
cmark_render_code_point(renderer, c);
|
56
|
+
}
|
57
|
+
break;
|
58
|
+
case 94: // '^'
|
59
|
+
cmark_render_ascii(renderer, "\\^{}");
|
60
|
+
break;
|
61
|
+
case 92: // '\\'
|
62
|
+
if (escape == URL) {
|
63
|
+
// / acts as path sep even on windows:
|
64
|
+
cmark_render_ascii(renderer, "/");
|
65
|
+
} else {
|
66
|
+
cmark_render_ascii(renderer, "\\textbackslash{}");
|
67
|
+
}
|
68
|
+
break;
|
69
|
+
case 124: // '|'
|
70
|
+
cmark_render_ascii(renderer, "\\textbar{}");
|
71
|
+
break;
|
72
|
+
case 60: // '<'
|
73
|
+
cmark_render_ascii(renderer, "\\textless{}");
|
74
|
+
break;
|
75
|
+
case 62: // '>'
|
76
|
+
cmark_render_ascii(renderer, "\\textgreater{}");
|
77
|
+
break;
|
78
|
+
case 91: // '['
|
79
|
+
case 93: // ']'
|
80
|
+
cmark_render_ascii(renderer, "{");
|
81
|
+
cmark_render_code_point(renderer, c);
|
82
|
+
cmark_render_ascii(renderer, "}");
|
83
|
+
break;
|
84
|
+
case 34: // '"'
|
85
|
+
cmark_render_ascii(renderer, "\\textquotedbl{}");
|
86
|
+
// requires \usepackage[T1]{fontenc}
|
87
|
+
break;
|
88
|
+
case 39: // '\''
|
89
|
+
cmark_render_ascii(renderer, "\\textquotesingle{}");
|
90
|
+
// requires \usepackage{textcomp}
|
91
|
+
break;
|
92
|
+
case 160: // nbsp
|
93
|
+
cmark_render_ascii(renderer, "~");
|
94
|
+
break;
|
95
|
+
case 8230: // hellip
|
96
|
+
cmark_render_ascii(renderer, "\\ldots{}");
|
97
|
+
break;
|
98
|
+
case 8216: // lsquo
|
99
|
+
if (escape == NORMAL) {
|
100
|
+
cmark_render_ascii(renderer, "`");
|
101
|
+
} else {
|
102
|
+
cmark_render_code_point(renderer, c);
|
103
|
+
}
|
104
|
+
break;
|
105
|
+
case 8217: // rsquo
|
106
|
+
if (escape == NORMAL) {
|
107
|
+
cmark_render_ascii(renderer, "\'");
|
108
|
+
} else {
|
109
|
+
cmark_render_code_point(renderer, c);
|
110
|
+
}
|
111
|
+
break;
|
112
|
+
case 8220: // ldquo
|
113
|
+
if (escape == NORMAL) {
|
114
|
+
cmark_render_ascii(renderer, "``");
|
115
|
+
} else {
|
116
|
+
cmark_render_code_point(renderer, c);
|
117
|
+
}
|
118
|
+
break;
|
119
|
+
case 8221: // rdquo
|
120
|
+
if (escape == NORMAL) {
|
121
|
+
cmark_render_ascii(renderer, "''");
|
122
|
+
} else {
|
123
|
+
cmark_render_code_point(renderer, c);
|
124
|
+
}
|
125
|
+
break;
|
126
|
+
case 8212: // emdash
|
127
|
+
if (escape == NORMAL) {
|
128
|
+
cmark_render_ascii(renderer, "---");
|
129
|
+
} else {
|
130
|
+
cmark_render_code_point(renderer, c);
|
131
|
+
}
|
132
|
+
break;
|
133
|
+
case 8211: // endash
|
134
|
+
if (escape == NORMAL) {
|
135
|
+
cmark_render_ascii(renderer, "--");
|
136
|
+
} else {
|
137
|
+
cmark_render_code_point(renderer, c);
|
138
|
+
}
|
139
|
+
break;
|
140
|
+
default:
|
141
|
+
cmark_render_code_point(renderer, c);
|
142
|
+
}
|
146
143
|
}
|
147
144
|
|
148
|
-
typedef enum
|
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
|
-
if (isemail) {
|
197
|
-
return EMAIL_AUTOLINK;
|
198
|
-
} else {
|
199
|
-
return URL_AUTOLINK;
|
200
|
-
}
|
201
|
-
} else {
|
202
|
-
return NORMAL_LINK;
|
203
|
-
}
|
145
|
+
typedef enum { NO_LINK, URL_AUTOLINK, EMAIL_AUTOLINK, NORMAL_LINK } link_type;
|
146
|
+
|
147
|
+
static link_type get_link_type(cmark_node *node) {
|
148
|
+
size_t title_len, url_len;
|
149
|
+
cmark_node *link_text;
|
150
|
+
char *realurl;
|
151
|
+
int realurllen;
|
152
|
+
bool isemail = false;
|
153
|
+
|
154
|
+
if (node->type != CMARK_NODE_LINK) {
|
155
|
+
return NO_LINK;
|
156
|
+
}
|
157
|
+
|
158
|
+
const char *url = cmark_node_get_url(node);
|
159
|
+
cmark_chunk url_chunk = cmark_chunk_literal(url);
|
160
|
+
|
161
|
+
url_len = safe_strlen(url);
|
162
|
+
if (url_len == 0 || scan_scheme(&url_chunk, 0) == 0) {
|
163
|
+
return NO_LINK;
|
164
|
+
}
|
165
|
+
|
166
|
+
const char *title = cmark_node_get_title(node);
|
167
|
+
title_len = safe_strlen(title);
|
168
|
+
// if it has a title, we can't treat it as an autolink:
|
169
|
+
if (title_len > 0) {
|
170
|
+
return NORMAL_LINK;
|
171
|
+
}
|
172
|
+
|
173
|
+
link_text = node->first_child;
|
174
|
+
cmark_consolidate_text_nodes(link_text);
|
175
|
+
realurl = (char *)url;
|
176
|
+
realurllen = url_len;
|
177
|
+
if (strncmp(realurl, "mailto:", 7) == 0) {
|
178
|
+
realurl += 7;
|
179
|
+
realurllen -= 7;
|
180
|
+
isemail = true;
|
181
|
+
}
|
182
|
+
if (realurllen == link_text->as.literal.len &&
|
183
|
+
strncmp(realurl, (char *)link_text->as.literal.data,
|
184
|
+
link_text->as.literal.len) == 0) {
|
185
|
+
if (isemail) {
|
186
|
+
return EMAIL_AUTOLINK;
|
187
|
+
} else {
|
188
|
+
return URL_AUTOLINK;
|
189
|
+
}
|
190
|
+
} else {
|
191
|
+
return NORMAL_LINK;
|
192
|
+
}
|
204
193
|
}
|
205
194
|
|
206
|
-
static int
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
}
|
218
|
-
return enumlevel;
|
195
|
+
static int S_get_enumlevel(cmark_node *node) {
|
196
|
+
int enumlevel = 0;
|
197
|
+
cmark_node *tmp = node;
|
198
|
+
while (tmp) {
|
199
|
+
if (tmp->type == CMARK_NODE_LIST &&
|
200
|
+
cmark_node_get_list_type(node) == CMARK_ORDERED_LIST) {
|
201
|
+
enumlevel++;
|
202
|
+
}
|
203
|
+
tmp = tmp->parent;
|
204
|
+
}
|
205
|
+
return enumlevel;
|
219
206
|
}
|
220
207
|
|
221
|
-
static int
|
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
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
break;
|
418
|
-
|
419
|
-
default:
|
420
|
-
assert(false);
|
421
|
-
break;
|
422
|
-
}
|
423
|
-
|
424
|
-
return 1;
|
208
|
+
static int S_render_node(cmark_renderer *renderer, cmark_node *node,
|
209
|
+
cmark_event_type ev_type, int options) {
|
210
|
+
int list_number;
|
211
|
+
char list_number_string[20];
|
212
|
+
bool entering = (ev_type == CMARK_EVENT_ENTER);
|
213
|
+
cmark_list_type list_type;
|
214
|
+
const char *roman_numerals[] = {"", "i", "ii", "iii", "iv", "v",
|
215
|
+
"vi", "vii", "viii", "ix", "x"};
|
216
|
+
|
217
|
+
// avoid warning about unused parameter:
|
218
|
+
(void)(options);
|
219
|
+
|
220
|
+
switch (node->type) {
|
221
|
+
case CMARK_NODE_DOCUMENT:
|
222
|
+
break;
|
223
|
+
|
224
|
+
case CMARK_NODE_BLOCK_QUOTE:
|
225
|
+
if (entering) {
|
226
|
+
LIT("\\begin{quote}");
|
227
|
+
CR();
|
228
|
+
} else {
|
229
|
+
LIT("\\end{quote}");
|
230
|
+
BLANKLINE();
|
231
|
+
}
|
232
|
+
break;
|
233
|
+
|
234
|
+
case CMARK_NODE_LIST:
|
235
|
+
list_type = cmark_node_get_list_type(node);
|
236
|
+
if (entering) {
|
237
|
+
LIT("\\begin{");
|
238
|
+
LIT(list_type == CMARK_ORDERED_LIST ? "enumerate" : "itemize");
|
239
|
+
LIT("}");
|
240
|
+
CR();
|
241
|
+
list_number = cmark_node_get_list_start(node);
|
242
|
+
if (list_number > 1) {
|
243
|
+
sprintf(list_number_string, "%d", list_number);
|
244
|
+
LIT("\\setcounter{enum");
|
245
|
+
LIT((char *)roman_numerals[S_get_enumlevel(node)]);
|
246
|
+
LIT("}{");
|
247
|
+
OUT(list_number_string, false, NORMAL);
|
248
|
+
LIT("}");
|
249
|
+
CR();
|
250
|
+
}
|
251
|
+
} else {
|
252
|
+
LIT("\\end{");
|
253
|
+
LIT(list_type == CMARK_ORDERED_LIST ? "enumerate" : "itemize");
|
254
|
+
LIT("}");
|
255
|
+
BLANKLINE();
|
256
|
+
}
|
257
|
+
break;
|
258
|
+
|
259
|
+
case CMARK_NODE_ITEM:
|
260
|
+
if (entering) {
|
261
|
+
LIT("\\item ");
|
262
|
+
} else {
|
263
|
+
CR();
|
264
|
+
}
|
265
|
+
break;
|
266
|
+
|
267
|
+
case CMARK_NODE_HEADER:
|
268
|
+
if (entering) {
|
269
|
+
switch (cmark_node_get_header_level(node)) {
|
270
|
+
case 1:
|
271
|
+
LIT("\\section");
|
272
|
+
break;
|
273
|
+
case 2:
|
274
|
+
LIT("\\subsection");
|
275
|
+
break;
|
276
|
+
case 3:
|
277
|
+
LIT("\\subsubsection");
|
278
|
+
break;
|
279
|
+
case 4:
|
280
|
+
LIT("\\paragraph");
|
281
|
+
break;
|
282
|
+
case 5:
|
283
|
+
LIT("\\subparagraph");
|
284
|
+
break;
|
285
|
+
}
|
286
|
+
LIT("{");
|
287
|
+
} else {
|
288
|
+
LIT("}");
|
289
|
+
BLANKLINE();
|
290
|
+
}
|
291
|
+
break;
|
292
|
+
|
293
|
+
case CMARK_NODE_CODE_BLOCK:
|
294
|
+
CR();
|
295
|
+
LIT("\\begin{verbatim}");
|
296
|
+
CR();
|
297
|
+
OUT(cmark_node_get_literal(node), false, LITERAL);
|
298
|
+
CR();
|
299
|
+
LIT("\\end{verbatim}");
|
300
|
+
BLANKLINE();
|
301
|
+
break;
|
302
|
+
|
303
|
+
case CMARK_NODE_HTML:
|
304
|
+
break;
|
305
|
+
|
306
|
+
case CMARK_NODE_HRULE:
|
307
|
+
BLANKLINE();
|
308
|
+
LIT("\\begin{center}\\rule{0.5\\linewidth}{\\linethickness}\\end{center}");
|
309
|
+
BLANKLINE();
|
310
|
+
break;
|
311
|
+
|
312
|
+
case CMARK_NODE_PARAGRAPH:
|
313
|
+
if (!entering) {
|
314
|
+
BLANKLINE();
|
315
|
+
}
|
316
|
+
break;
|
317
|
+
|
318
|
+
case CMARK_NODE_TEXT:
|
319
|
+
OUT(cmark_node_get_literal(node), true, NORMAL);
|
320
|
+
break;
|
321
|
+
|
322
|
+
case CMARK_NODE_LINEBREAK:
|
323
|
+
LIT("\\\\");
|
324
|
+
CR();
|
325
|
+
break;
|
326
|
+
|
327
|
+
case CMARK_NODE_SOFTBREAK:
|
328
|
+
if (renderer->width == 0) {
|
329
|
+
CR();
|
330
|
+
} else {
|
331
|
+
OUT(" ", true, NORMAL);
|
332
|
+
}
|
333
|
+
break;
|
334
|
+
|
335
|
+
case CMARK_NODE_CODE:
|
336
|
+
LIT("\\texttt{");
|
337
|
+
OUT(cmark_node_get_literal(node), false, NORMAL);
|
338
|
+
LIT("}");
|
339
|
+
break;
|
340
|
+
|
341
|
+
case CMARK_NODE_INLINE_HTML:
|
342
|
+
break;
|
343
|
+
|
344
|
+
case CMARK_NODE_STRONG:
|
345
|
+
if (entering) {
|
346
|
+
LIT("\\textbf{");
|
347
|
+
} else {
|
348
|
+
LIT("}");
|
349
|
+
}
|
350
|
+
break;
|
351
|
+
|
352
|
+
case CMARK_NODE_EMPH:
|
353
|
+
if (entering) {
|
354
|
+
LIT("\\emph{");
|
355
|
+
} else {
|
356
|
+
LIT("}");
|
357
|
+
}
|
358
|
+
break;
|
359
|
+
|
360
|
+
case CMARK_NODE_LINK:
|
361
|
+
if (entering) {
|
362
|
+
const char *url = cmark_node_get_url(node);
|
363
|
+
// requires \usepackage{hyperref}
|
364
|
+
switch (get_link_type(node)) {
|
365
|
+
case URL_AUTOLINK:
|
366
|
+
LIT("\\url{");
|
367
|
+
OUT(url, false, URL);
|
368
|
+
break;
|
369
|
+
case EMAIL_AUTOLINK:
|
370
|
+
LIT("\\href{");
|
371
|
+
OUT(url, false, URL);
|
372
|
+
LIT("}\\nolinkurl{");
|
373
|
+
break;
|
374
|
+
case NORMAL_LINK:
|
375
|
+
LIT("\\href{");
|
376
|
+
OUT(url, false, URL);
|
377
|
+
LIT("}{");
|
378
|
+
break;
|
379
|
+
case NO_LINK:
|
380
|
+
LIT("{"); // error?
|
381
|
+
}
|
382
|
+
} else {
|
383
|
+
LIT("}");
|
384
|
+
}
|
385
|
+
|
386
|
+
break;
|
387
|
+
|
388
|
+
case CMARK_NODE_IMAGE:
|
389
|
+
if (entering) {
|
390
|
+
LIT("\\protect\\includegraphics{");
|
391
|
+
// requires \include{graphicx}
|
392
|
+
OUT(cmark_node_get_url(node), false, URL);
|
393
|
+
LIT("}");
|
394
|
+
return 0;
|
395
|
+
}
|
396
|
+
break;
|
397
|
+
|
398
|
+
default:
|
399
|
+
assert(false);
|
400
|
+
break;
|
401
|
+
}
|
402
|
+
|
403
|
+
return 1;
|
425
404
|
}
|
426
405
|
|
427
|
-
char *cmark_render_latex(cmark_node *root, int options, int width)
|
428
|
-
|
429
|
-
return cmark_render(root, options, width, outc, S_render_node);
|
406
|
+
char *cmark_render_latex(cmark_node *root, int options, int width) {
|
407
|
+
return cmark_render(root, options, width, outc, S_render_node);
|
430
408
|
}
|