commonmarker 0.23.6 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +70 -212
  3. data/commonmarker.gemspec +34 -31
  4. data/ext/commonmarker/Cargo.toml +12 -0
  5. data/ext/commonmarker/_util.rb +102 -0
  6. data/ext/commonmarker/extconf.rb +4 -5
  7. data/ext/commonmarker/src/comrak_options.rs +107 -0
  8. data/ext/commonmarker/src/lib.rs +27 -0
  9. data/lib/commonmarker/config.rb +58 -37
  10. data/lib/commonmarker/extension.rb +14 -0
  11. data/lib/commonmarker/renderer.rb +1 -127
  12. data/lib/commonmarker/version.rb +2 -2
  13. data/lib/commonmarker.rb +19 -32
  14. metadata +33 -177
  15. data/Rakefile +0 -109
  16. data/bin/commonmarker +0 -118
  17. data/ext/commonmarker/arena.c +0 -103
  18. data/ext/commonmarker/autolink.c +0 -456
  19. data/ext/commonmarker/autolink.h +0 -8
  20. data/ext/commonmarker/blocks.c +0 -1596
  21. data/ext/commonmarker/buffer.c +0 -278
  22. data/ext/commonmarker/buffer.h +0 -116
  23. data/ext/commonmarker/case_fold_switch.inc +0 -4327
  24. data/ext/commonmarker/chunk.h +0 -135
  25. data/ext/commonmarker/cmark-gfm-core-extensions.h +0 -54
  26. data/ext/commonmarker/cmark-gfm-extension_api.h +0 -736
  27. data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
  28. data/ext/commonmarker/cmark-gfm.h +0 -817
  29. data/ext/commonmarker/cmark-gfm_export.h +0 -42
  30. data/ext/commonmarker/cmark-gfm_version.h +0 -7
  31. data/ext/commonmarker/cmark.c +0 -55
  32. data/ext/commonmarker/cmark_ctype.c +0 -44
  33. data/ext/commonmarker/cmark_ctype.h +0 -33
  34. data/ext/commonmarker/commonmark.c +0 -529
  35. data/ext/commonmarker/commonmarker.c +0 -1307
  36. data/ext/commonmarker/commonmarker.h +0 -16
  37. data/ext/commonmarker/config.h +0 -76
  38. data/ext/commonmarker/core-extensions.c +0 -27
  39. data/ext/commonmarker/entities.inc +0 -2138
  40. data/ext/commonmarker/ext_scanners.c +0 -879
  41. data/ext/commonmarker/ext_scanners.h +0 -24
  42. data/ext/commonmarker/footnotes.c +0 -63
  43. data/ext/commonmarker/footnotes.h +0 -27
  44. data/ext/commonmarker/houdini.h +0 -57
  45. data/ext/commonmarker/houdini_href_e.c +0 -100
  46. data/ext/commonmarker/houdini_html_e.c +0 -66
  47. data/ext/commonmarker/houdini_html_u.c +0 -149
  48. data/ext/commonmarker/html.c +0 -486
  49. data/ext/commonmarker/html.h +0 -27
  50. data/ext/commonmarker/inlines.c +0 -1716
  51. data/ext/commonmarker/inlines.h +0 -29
  52. data/ext/commonmarker/iterator.c +0 -159
  53. data/ext/commonmarker/iterator.h +0 -26
  54. data/ext/commonmarker/latex.c +0 -466
  55. data/ext/commonmarker/linked_list.c +0 -37
  56. data/ext/commonmarker/man.c +0 -278
  57. data/ext/commonmarker/map.c +0 -122
  58. data/ext/commonmarker/map.h +0 -41
  59. data/ext/commonmarker/node.c +0 -979
  60. data/ext/commonmarker/node.h +0 -125
  61. data/ext/commonmarker/parser.h +0 -58
  62. data/ext/commonmarker/plaintext.c +0 -235
  63. data/ext/commonmarker/plugin.c +0 -36
  64. data/ext/commonmarker/plugin.h +0 -34
  65. data/ext/commonmarker/references.c +0 -42
  66. data/ext/commonmarker/references.h +0 -26
  67. data/ext/commonmarker/registry.c +0 -63
  68. data/ext/commonmarker/registry.h +0 -24
  69. data/ext/commonmarker/render.c +0 -205
  70. data/ext/commonmarker/render.h +0 -62
  71. data/ext/commonmarker/scanners.c +0 -10508
  72. data/ext/commonmarker/scanners.h +0 -62
  73. data/ext/commonmarker/scanners.re +0 -341
  74. data/ext/commonmarker/strikethrough.c +0 -167
  75. data/ext/commonmarker/strikethrough.h +0 -9
  76. data/ext/commonmarker/syntax_extension.c +0 -149
  77. data/ext/commonmarker/syntax_extension.h +0 -34
  78. data/ext/commonmarker/table.c +0 -848
  79. data/ext/commonmarker/table.h +0 -12
  80. data/ext/commonmarker/tagfilter.c +0 -60
  81. data/ext/commonmarker/tagfilter.h +0 -8
  82. data/ext/commonmarker/tasklist.c +0 -156
  83. data/ext/commonmarker/tasklist.h +0 -8
  84. data/ext/commonmarker/utf8.c +0 -317
  85. data/ext/commonmarker/utf8.h +0 -35
  86. data/ext/commonmarker/xml.c +0 -181
  87. data/lib/commonmarker/node/inspect.rb +0 -47
  88. data/lib/commonmarker/node.rb +0 -83
  89. data/lib/commonmarker/renderer/html_renderer.rb +0 -252
@@ -1,278 +0,0 @@
1
- #include <stdlib.h>
2
- #include <stdio.h>
3
- #include <string.h>
4
- #include <assert.h>
5
-
6
- #include "config.h"
7
- #include "cmark-gfm.h"
8
- #include "node.h"
9
- #include "buffer.h"
10
- #include "utf8.h"
11
- #include "render.h"
12
- #include "syntax_extension.h"
13
-
14
- #define OUT(s, wrap, escaping) renderer->out(renderer, node, s, wrap, escaping)
15
- #define LIT(s) renderer->out(renderer, node, s, false, LITERAL)
16
- #define CR() renderer->cr(renderer)
17
- #define BLANKLINE() renderer->blankline(renderer)
18
- #define LIST_NUMBER_SIZE 20
19
-
20
- // Functions to convert cmark_nodes to groff man strings.
21
- static void S_outc(cmark_renderer *renderer, cmark_node *node,
22
- cmark_escaping escape, int32_t c,
23
- unsigned char nextc) {
24
- (void)(nextc);
25
-
26
- if (escape == LITERAL) {
27
- cmark_render_code_point(renderer, c);
28
- return;
29
- }
30
-
31
- switch (c) {
32
- case 46:
33
- if (renderer->begin_line) {
34
- cmark_render_ascii(renderer, "\\&.");
35
- } else {
36
- cmark_render_code_point(renderer, c);
37
- }
38
- break;
39
- case 39:
40
- if (renderer->begin_line) {
41
- cmark_render_ascii(renderer, "\\&'");
42
- } else {
43
- cmark_render_code_point(renderer, c);
44
- }
45
- break;
46
- case 45:
47
- cmark_render_ascii(renderer, "\\-");
48
- break;
49
- case 92:
50
- cmark_render_ascii(renderer, "\\e");
51
- break;
52
- case 8216: // left single quote
53
- cmark_render_ascii(renderer, "\\[oq]");
54
- break;
55
- case 8217: // right single quote
56
- cmark_render_ascii(renderer, "\\[cq]");
57
- break;
58
- case 8220: // left double quote
59
- cmark_render_ascii(renderer, "\\[lq]");
60
- break;
61
- case 8221: // right double quote
62
- cmark_render_ascii(renderer, "\\[rq]");
63
- break;
64
- case 8212: // em dash
65
- cmark_render_ascii(renderer, "\\[em]");
66
- break;
67
- case 8211: // en dash
68
- cmark_render_ascii(renderer, "\\[en]");
69
- break;
70
- default:
71
- cmark_render_code_point(renderer, c);
72
- }
73
- }
74
-
75
- static int S_render_node(cmark_renderer *renderer, cmark_node *node,
76
- cmark_event_type ev_type, int options) {
77
- cmark_node *tmp;
78
- int list_number;
79
- bool entering = (ev_type == CMARK_EVENT_ENTER);
80
- bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options);
81
-
82
- if (node->extension && node->extension->man_render_func) {
83
- node->extension->man_render_func(node->extension, renderer, node, ev_type, options);
84
- return 1;
85
- }
86
-
87
- switch (node->type) {
88
- case CMARK_NODE_DOCUMENT:
89
- if (entering) {
90
- /* Define a strikethrough macro */
91
- /* Commenting out because this makes tests fail
92
- LIT(".de ST");
93
- CR();
94
- LIT(".nr ww \\w'\\\\$1'");
95
- CR();
96
- LIT("\\Z@\\v'-.25m'\\l'\\\\n[ww]u'@\\\\$1");
97
- CR();
98
- LIT("..");
99
- CR();
100
- */
101
- }
102
- break;
103
-
104
- case CMARK_NODE_BLOCK_QUOTE:
105
- if (entering) {
106
- CR();
107
- LIT(".RS");
108
- CR();
109
- } else {
110
- CR();
111
- LIT(".RE");
112
- CR();
113
- }
114
- break;
115
-
116
- case CMARK_NODE_LIST:
117
- break;
118
-
119
- case CMARK_NODE_ITEM:
120
- if (entering) {
121
- CR();
122
- LIT(".IP ");
123
- if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
124
- LIT("\\[bu] 2");
125
- } else {
126
- list_number = cmark_node_get_list_start(node->parent);
127
- tmp = node;
128
- while (tmp->prev) {
129
- tmp = tmp->prev;
130
- list_number += 1;
131
- }
132
- char list_number_s[LIST_NUMBER_SIZE];
133
- snprintf(list_number_s, LIST_NUMBER_SIZE, "\"%d.\" 4", list_number);
134
- LIT(list_number_s);
135
- }
136
- CR();
137
- } else {
138
- CR();
139
- }
140
- break;
141
-
142
- case CMARK_NODE_HEADING:
143
- if (entering) {
144
- CR();
145
- LIT(cmark_node_get_heading_level(node) == 1 ? ".SH" : ".SS");
146
- CR();
147
- } else {
148
- CR();
149
- }
150
- break;
151
-
152
- case CMARK_NODE_CODE_BLOCK:
153
- CR();
154
- LIT(".IP\n.nf\n\\f[C]\n");
155
- OUT(cmark_node_get_literal(node), false, NORMAL);
156
- CR();
157
- LIT("\\f[]\n.fi");
158
- CR();
159
- break;
160
-
161
- case CMARK_NODE_HTML_BLOCK:
162
- break;
163
-
164
- case CMARK_NODE_CUSTOM_BLOCK:
165
- CR();
166
- OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node),
167
- false, LITERAL);
168
- CR();
169
- break;
170
-
171
- case CMARK_NODE_THEMATIC_BREAK:
172
- CR();
173
- LIT(".PP\n * * * * *");
174
- CR();
175
- break;
176
-
177
- case CMARK_NODE_PARAGRAPH:
178
- if (entering) {
179
- // no blank line if first paragraph in list:
180
- if (node->parent && node->parent->type == CMARK_NODE_ITEM &&
181
- node->prev == NULL) {
182
- // no blank line or .PP
183
- } else {
184
- CR();
185
- LIT(".PP");
186
- CR();
187
- }
188
- } else {
189
- CR();
190
- }
191
- break;
192
-
193
- case CMARK_NODE_TEXT:
194
- OUT(cmark_node_get_literal(node), allow_wrap, NORMAL);
195
- break;
196
-
197
- case CMARK_NODE_LINEBREAK:
198
- LIT(".PD 0\n.P\n.PD");
199
- CR();
200
- break;
201
-
202
- case CMARK_NODE_SOFTBREAK:
203
- if (options & CMARK_OPT_HARDBREAKS) {
204
- LIT(".PD 0\n.P\n.PD");
205
- CR();
206
- } else if (renderer->width == 0 && !(CMARK_OPT_NOBREAKS & options)) {
207
- CR();
208
- } else {
209
- OUT(" ", allow_wrap, LITERAL);
210
- }
211
- break;
212
-
213
- case CMARK_NODE_CODE:
214
- LIT("\\f[C]");
215
- OUT(cmark_node_get_literal(node), allow_wrap, NORMAL);
216
- LIT("\\f[]");
217
- break;
218
-
219
- case CMARK_NODE_HTML_INLINE:
220
- break;
221
-
222
- case CMARK_NODE_CUSTOM_INLINE:
223
- OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node),
224
- false, LITERAL);
225
- break;
226
-
227
- case CMARK_NODE_STRONG:
228
- if (entering) {
229
- LIT("\\f[B]");
230
- } else {
231
- LIT("\\f[]");
232
- }
233
- break;
234
-
235
- case CMARK_NODE_EMPH:
236
- if (entering) {
237
- LIT("\\f[I]");
238
- } else {
239
- LIT("\\f[]");
240
- }
241
- break;
242
-
243
- case CMARK_NODE_LINK:
244
- if (!entering) {
245
- LIT(" (");
246
- OUT(cmark_node_get_url(node), allow_wrap, URL);
247
- LIT(")");
248
- }
249
- break;
250
-
251
- case CMARK_NODE_IMAGE:
252
- if (entering) {
253
- LIT("[IMAGE: ");
254
- } else {
255
- LIT("]");
256
- }
257
- break;
258
-
259
- case CMARK_NODE_FOOTNOTE_DEFINITION:
260
- case CMARK_NODE_FOOTNOTE_REFERENCE:
261
- // TODO
262
- break;
263
-
264
- default:
265
- assert(false);
266
- break;
267
- }
268
-
269
- return 1;
270
- }
271
-
272
- char *cmark_render_man(cmark_node *root, int options, int width) {
273
- return cmark_render_man_with_mem(root, options, width, cmark_node_mem(root));
274
- }
275
-
276
- char *cmark_render_man_with_mem(cmark_node *root, int options, int width, cmark_mem *mem) {
277
- return cmark_render(mem, root, options, width, S_outc, S_render_node);
278
- }
@@ -1,122 +0,0 @@
1
- #include "map.h"
2
- #include "utf8.h"
3
- #include "parser.h"
4
-
5
- // normalize map label: collapse internal whitespace to single space,
6
- // remove leading/trailing whitespace, case fold
7
- // Return NULL if the label is actually empty (i.e. composed solely from
8
- // whitespace)
9
- unsigned char *normalize_map_label(cmark_mem *mem, cmark_chunk *ref) {
10
- cmark_strbuf normalized = CMARK_BUF_INIT(mem);
11
- unsigned char *result;
12
-
13
- if (ref == NULL)
14
- return NULL;
15
-
16
- if (ref->len == 0)
17
- return NULL;
18
-
19
- cmark_utf8proc_case_fold(&normalized, ref->data, ref->len);
20
- cmark_strbuf_trim(&normalized);
21
- cmark_strbuf_normalize_whitespace(&normalized);
22
-
23
- result = cmark_strbuf_detach(&normalized);
24
- assert(result);
25
-
26
- if (result[0] == '\0') {
27
- mem->free(result);
28
- return NULL;
29
- }
30
-
31
- return result;
32
- }
33
-
34
- static int
35
- labelcmp(const unsigned char *a, const unsigned char *b) {
36
- return strcmp((const char *)a, (const char *)b);
37
- }
38
-
39
- static int
40
- refcmp(const void *p1, const void *p2) {
41
- cmark_map_entry *r1 = *(cmark_map_entry **)p1;
42
- cmark_map_entry *r2 = *(cmark_map_entry **)p2;
43
- int res = labelcmp(r1->label, r2->label);
44
- return res ? res : ((int)r1->age - (int)r2->age);
45
- }
46
-
47
- static int
48
- refsearch(const void *label, const void *p2) {
49
- cmark_map_entry *ref = *(cmark_map_entry **)p2;
50
- return labelcmp((const unsigned char *)label, ref->label);
51
- }
52
-
53
- static void sort_map(cmark_map *map) {
54
- unsigned int i = 0, last = 0, size = map->size;
55
- cmark_map_entry *r = map->refs, **sorted = NULL;
56
-
57
- sorted = (cmark_map_entry **)map->mem->calloc(size, sizeof(cmark_map_entry *));
58
- while (r) {
59
- sorted[i++] = r;
60
- r = r->next;
61
- }
62
-
63
- qsort(sorted, size, sizeof(cmark_map_entry *), refcmp);
64
-
65
- for (i = 1; i < size; i++) {
66
- if (labelcmp(sorted[i]->label, sorted[last]->label) != 0)
67
- sorted[++last] = sorted[i];
68
- }
69
-
70
- map->sorted = sorted;
71
- map->size = last + 1;
72
- }
73
-
74
- cmark_map_entry *cmark_map_lookup(cmark_map *map, cmark_chunk *label) {
75
- cmark_map_entry **ref = NULL;
76
- unsigned char *norm;
77
-
78
- if (label->len < 1 || label->len > MAX_LINK_LABEL_LENGTH)
79
- return NULL;
80
-
81
- if (map == NULL || !map->size)
82
- return NULL;
83
-
84
- norm = normalize_map_label(map->mem, label);
85
- if (norm == NULL)
86
- return NULL;
87
-
88
- if (!map->sorted)
89
- sort_map(map);
90
-
91
- ref = (cmark_map_entry **)bsearch(norm, map->sorted, map->size, sizeof(cmark_map_entry *), refsearch);
92
- map->mem->free(norm);
93
-
94
- if (!ref)
95
- return NULL;
96
-
97
- return ref[0];
98
- }
99
-
100
- void cmark_map_free(cmark_map *map) {
101
- cmark_map_entry *ref;
102
-
103
- if (map == NULL)
104
- return;
105
-
106
- ref = map->refs;
107
- while (ref) {
108
- cmark_map_entry *next = ref->next;
109
- map->free(map, ref);
110
- ref = next;
111
- }
112
-
113
- map->mem->free(map->sorted);
114
- map->mem->free(map);
115
- }
116
-
117
- cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free) {
118
- cmark_map *map = (cmark_map *)mem->calloc(1, sizeof(cmark_map));
119
- map->mem = mem;
120
- map->free = free;
121
- return map;
122
- }
@@ -1,41 +0,0 @@
1
- #ifndef CMARK_MAP_H
2
- #define CMARK_MAP_H
3
-
4
- #include "chunk.h"
5
-
6
- #ifdef __cplusplus
7
- extern "C" {
8
- #endif
9
-
10
- struct cmark_map_entry {
11
- struct cmark_map_entry *next;
12
- unsigned char *label;
13
- unsigned int age;
14
- };
15
-
16
- typedef struct cmark_map_entry cmark_map_entry;
17
-
18
- struct cmark_map;
19
-
20
- typedef void (*cmark_map_free_f)(struct cmark_map *, cmark_map_entry *);
21
-
22
- struct cmark_map {
23
- cmark_mem *mem;
24
- cmark_map_entry *refs;
25
- cmark_map_entry **sorted;
26
- unsigned int size;
27
- cmark_map_free_f free;
28
- };
29
-
30
- typedef struct cmark_map cmark_map;
31
-
32
- unsigned char *normalize_map_label(cmark_mem *mem, cmark_chunk *ref);
33
- cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free);
34
- void cmark_map_free(cmark_map *map);
35
- cmark_map_entry *cmark_map_lookup(cmark_map *map, cmark_chunk *label);
36
-
37
- #ifdef __cplusplus
38
- }
39
- #endif
40
-
41
- #endif