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.

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