commonmarker 0.23.9 → 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 +57 -38
  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 +14 -29
  14. metadata +37 -181
  15. data/Rakefile +0 -109
  16. data/bin/commonmarker +0 -118
  17. data/ext/commonmarker/arena.c +0 -104
  18. data/ext/commonmarker/autolink.c +0 -508
  19. data/ext/commonmarker/autolink.h +0 -8
  20. data/ext/commonmarker/blocks.c +0 -1620
  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 -737
  27. data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
  28. data/ext/commonmarker/cmark-gfm.h +0 -833
  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 -514
  35. data/ext/commonmarker/commonmarker.c +0 -1308
  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 -502
  49. data/ext/commonmarker/html.h +0 -27
  50. data/ext/commonmarker/inlines.c +0 -1788
  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 -468
  55. data/ext/commonmarker/linked_list.c +0 -37
  56. data/ext/commonmarker/man.c +0 -274
  57. data/ext/commonmarker/map.c +0 -129
  58. data/ext/commonmarker/map.h +0 -44
  59. data/ext/commonmarker/node.c +0 -1044
  60. data/ext/commonmarker/node.h +0 -166
  61. data/ext/commonmarker/parser.h +0 -59
  62. data/ext/commonmarker/plaintext.c +0 -218
  63. data/ext/commonmarker/plugin.c +0 -36
  64. data/ext/commonmarker/plugin.h +0 -34
  65. data/ext/commonmarker/references.c +0 -43
  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 -213
  70. data/ext/commonmarker/render.h +0 -62
  71. data/ext/commonmarker/scanners.c +0 -14056
  72. data/ext/commonmarker/scanners.h +0 -70
  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 -872
  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 -182
  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 -256
@@ -1,274 +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
- int list_number;
78
- bool entering = (ev_type == CMARK_EVENT_ENTER);
79
- bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options);
80
-
81
- if (node->extension && node->extension->man_render_func) {
82
- node->extension->man_render_func(node->extension, renderer, node, ev_type, options);
83
- return 1;
84
- }
85
-
86
- switch (node->type) {
87
- case CMARK_NODE_DOCUMENT:
88
- if (entering) {
89
- /* Define a strikethrough macro */
90
- /* Commenting out because this makes tests fail
91
- LIT(".de ST");
92
- CR();
93
- LIT(".nr ww \\w'\\\\$1'");
94
- CR();
95
- LIT("\\Z@\\v'-.25m'\\l'\\\\n[ww]u'@\\\\$1");
96
- CR();
97
- LIT("..");
98
- CR();
99
- */
100
- }
101
- break;
102
-
103
- case CMARK_NODE_BLOCK_QUOTE:
104
- if (entering) {
105
- CR();
106
- LIT(".RS");
107
- CR();
108
- } else {
109
- CR();
110
- LIT(".RE");
111
- CR();
112
- }
113
- break;
114
-
115
- case CMARK_NODE_LIST:
116
- break;
117
-
118
- case CMARK_NODE_ITEM:
119
- if (entering) {
120
- CR();
121
- LIT(".IP ");
122
- if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
123
- LIT("\\[bu] 2");
124
- } else {
125
- list_number = cmark_node_get_item_index(node);
126
- char list_number_s[LIST_NUMBER_SIZE];
127
- snprintf(list_number_s, LIST_NUMBER_SIZE, "\"%d.\" 4", list_number);
128
- LIT(list_number_s);
129
- }
130
- CR();
131
- } else {
132
- CR();
133
- }
134
- break;
135
-
136
- case CMARK_NODE_HEADING:
137
- if (entering) {
138
- CR();
139
- LIT(cmark_node_get_heading_level(node) == 1 ? ".SH" : ".SS");
140
- CR();
141
- } else {
142
- CR();
143
- }
144
- break;
145
-
146
- case CMARK_NODE_CODE_BLOCK:
147
- CR();
148
- LIT(".IP\n.nf\n\\f[C]\n");
149
- OUT(cmark_node_get_literal(node), false, NORMAL);
150
- CR();
151
- LIT("\\f[]\n.fi");
152
- CR();
153
- break;
154
-
155
- case CMARK_NODE_HTML_BLOCK:
156
- break;
157
-
158
- case CMARK_NODE_CUSTOM_BLOCK:
159
- CR();
160
- OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node),
161
- false, LITERAL);
162
- CR();
163
- break;
164
-
165
- case CMARK_NODE_THEMATIC_BREAK:
166
- CR();
167
- LIT(".PP\n * * * * *");
168
- CR();
169
- break;
170
-
171
- case CMARK_NODE_PARAGRAPH:
172
- if (entering) {
173
- // no blank line if first paragraph in list:
174
- if (node->parent && node->parent->type == CMARK_NODE_ITEM &&
175
- node->prev == NULL) {
176
- // no blank line or .PP
177
- } else {
178
- CR();
179
- LIT(".PP");
180
- CR();
181
- }
182
- } else {
183
- CR();
184
- }
185
- break;
186
-
187
- case CMARK_NODE_TEXT:
188
- OUT(cmark_node_get_literal(node), allow_wrap, NORMAL);
189
- break;
190
-
191
- case CMARK_NODE_LINEBREAK:
192
- LIT(".PD 0\n.P\n.PD");
193
- CR();
194
- break;
195
-
196
- case CMARK_NODE_SOFTBREAK:
197
- if (options & CMARK_OPT_HARDBREAKS) {
198
- LIT(".PD 0\n.P\n.PD");
199
- CR();
200
- } else if (renderer->width == 0 && !(CMARK_OPT_NOBREAKS & options)) {
201
- CR();
202
- } else {
203
- OUT(" ", allow_wrap, LITERAL);
204
- }
205
- break;
206
-
207
- case CMARK_NODE_CODE:
208
- LIT("\\f[C]");
209
- OUT(cmark_node_get_literal(node), allow_wrap, NORMAL);
210
- LIT("\\f[]");
211
- break;
212
-
213
- case CMARK_NODE_HTML_INLINE:
214
- break;
215
-
216
- case CMARK_NODE_CUSTOM_INLINE:
217
- OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node),
218
- false, LITERAL);
219
- break;
220
-
221
- case CMARK_NODE_STRONG:
222
- if (node->parent == NULL || node->parent->type != CMARK_NODE_STRONG) {
223
- if (entering) {
224
- LIT("\\f[B]");
225
- } else {
226
- LIT("\\f[]");
227
- }
228
- }
229
- break;
230
-
231
- case CMARK_NODE_EMPH:
232
- if (entering) {
233
- LIT("\\f[I]");
234
- } else {
235
- LIT("\\f[]");
236
- }
237
- break;
238
-
239
- case CMARK_NODE_LINK:
240
- if (!entering) {
241
- LIT(" (");
242
- OUT(cmark_node_get_url(node), allow_wrap, URL);
243
- LIT(")");
244
- }
245
- break;
246
-
247
- case CMARK_NODE_IMAGE:
248
- if (entering) {
249
- LIT("[IMAGE: ");
250
- } else {
251
- LIT("]");
252
- }
253
- break;
254
-
255
- case CMARK_NODE_FOOTNOTE_DEFINITION:
256
- case CMARK_NODE_FOOTNOTE_REFERENCE:
257
- // TODO
258
- break;
259
-
260
- default:
261
- assert(false);
262
- break;
263
- }
264
-
265
- return 1;
266
- }
267
-
268
- char *cmark_render_man(cmark_node *root, int options, int width) {
269
- return cmark_render_man_with_mem(root, options, width, cmark_node_mem(root));
270
- }
271
-
272
- char *cmark_render_man_with_mem(cmark_node *root, int options, int width, cmark_mem *mem) {
273
- return cmark_render(mem, root, options, width, S_outc, S_render_node);
274
- }
@@ -1,129 +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
- size_t 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
- cmark_map_entry *r = NULL;
77
- unsigned char *norm;
78
-
79
- if (label->len < 1 || label->len > MAX_LINK_LABEL_LENGTH)
80
- return NULL;
81
-
82
- if (map == NULL || !map->size)
83
- return NULL;
84
-
85
- norm = normalize_map_label(map->mem, label);
86
- if (norm == NULL)
87
- return NULL;
88
-
89
- if (!map->sorted)
90
- sort_map(map);
91
-
92
- ref = (cmark_map_entry **)bsearch(norm, map->sorted, map->size, sizeof(cmark_map_entry *), refsearch);
93
- map->mem->free(norm);
94
-
95
- if (ref != NULL) {
96
- r = ref[0];
97
- /* Check for expansion limit */
98
- if (r->size > map->max_ref_size - map->ref_size)
99
- return NULL;
100
- map->ref_size += r->size;
101
- }
102
-
103
- return r;
104
- }
105
-
106
- void cmark_map_free(cmark_map *map) {
107
- cmark_map_entry *ref;
108
-
109
- if (map == NULL)
110
- return;
111
-
112
- ref = map->refs;
113
- while (ref) {
114
- cmark_map_entry *next = ref->next;
115
- map->free(map, ref);
116
- ref = next;
117
- }
118
-
119
- map->mem->free(map->sorted);
120
- map->mem->free(map);
121
- }
122
-
123
- cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free) {
124
- cmark_map *map = (cmark_map *)mem->calloc(1, sizeof(cmark_map));
125
- map->mem = mem;
126
- map->free = free;
127
- map->max_ref_size = UINT_MAX;
128
- return map;
129
- }
@@ -1,44 +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
- size_t age;
14
- size_t size;
15
- };
16
-
17
- typedef struct cmark_map_entry cmark_map_entry;
18
-
19
- struct cmark_map;
20
-
21
- typedef void (*cmark_map_free_f)(struct cmark_map *, cmark_map_entry *);
22
-
23
- struct cmark_map {
24
- cmark_mem *mem;
25
- cmark_map_entry *refs;
26
- cmark_map_entry **sorted;
27
- size_t size;
28
- size_t ref_size;
29
- size_t max_ref_size;
30
- cmark_map_free_f free;
31
- };
32
-
33
- typedef struct cmark_map cmark_map;
34
-
35
- unsigned char *normalize_map_label(cmark_mem *mem, cmark_chunk *ref);
36
- cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free);
37
- void cmark_map_free(cmark_map *map);
38
- cmark_map_entry *cmark_map_lookup(cmark_map *map, cmark_chunk *label);
39
-
40
- #ifdef __cplusplus
41
- }
42
- #endif
43
-
44
- #endif