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,278 +0,0 @@
1
- #include <stdarg.h>
2
- #include <string.h>
3
- #include <assert.h>
4
- #include <string.h>
5
- #include <stdio.h>
6
- #include <stdlib.h>
7
- #include <stdint.h>
8
- #include <limits.h>
9
-
10
- #include "config.h"
11
- #include "cmark_ctype.h"
12
- #include "buffer.h"
13
-
14
- /* Used as default value for cmark_strbuf->ptr so that people can always
15
- * assume ptr is non-NULL and zero terminated even for new cmark_strbufs.
16
- */
17
- unsigned char cmark_strbuf__initbuf[1];
18
-
19
- #ifndef MIN
20
- #define MIN(x, y) ((x < y) ? x : y)
21
- #endif
22
-
23
- void cmark_strbuf_init(cmark_mem *mem, cmark_strbuf *buf,
24
- bufsize_t initial_size) {
25
- buf->mem = mem;
26
- buf->asize = 0;
27
- buf->size = 0;
28
- buf->ptr = cmark_strbuf__initbuf;
29
-
30
- if (initial_size > 0)
31
- cmark_strbuf_grow(buf, initial_size);
32
- }
33
-
34
- static CMARK_INLINE void S_strbuf_grow_by(cmark_strbuf *buf, bufsize_t add) {
35
- cmark_strbuf_grow(buf, buf->size + add);
36
- }
37
-
38
- void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size) {
39
- assert(target_size > 0);
40
-
41
- if (target_size < buf->asize)
42
- return;
43
-
44
- if (target_size > (bufsize_t)(INT32_MAX / 2)) {
45
- fprintf(stderr,
46
- "[cmark] cmark_strbuf_grow requests buffer with size > %d, aborting\n",
47
- (INT32_MAX / 2));
48
- abort();
49
- }
50
-
51
- /* Oversize the buffer by 50% to guarantee amortized linear time
52
- * complexity on append operations. */
53
- bufsize_t new_size = target_size + target_size / 2;
54
- new_size += 1;
55
- new_size = (new_size + 7) & ~7;
56
-
57
- buf->ptr = (unsigned char *)buf->mem->realloc(buf->asize ? buf->ptr : NULL,
58
- new_size);
59
- buf->asize = new_size;
60
- }
61
-
62
- bufsize_t cmark_strbuf_len(const cmark_strbuf *buf) { return buf->size; }
63
-
64
- void cmark_strbuf_free(cmark_strbuf *buf) {
65
- if (!buf)
66
- return;
67
-
68
- if (buf->ptr != cmark_strbuf__initbuf)
69
- buf->mem->free(buf->ptr);
70
-
71
- cmark_strbuf_init(buf->mem, buf, 0);
72
- }
73
-
74
- void cmark_strbuf_clear(cmark_strbuf *buf) {
75
- buf->size = 0;
76
-
77
- if (buf->asize > 0)
78
- buf->ptr[0] = '\0';
79
- }
80
-
81
- void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,
82
- bufsize_t len) {
83
- if (len <= 0 || data == NULL) {
84
- cmark_strbuf_clear(buf);
85
- } else {
86
- if (data != buf->ptr) {
87
- if (len >= buf->asize)
88
- cmark_strbuf_grow(buf, len);
89
- memmove(buf->ptr, data, len);
90
- }
91
- buf->size = len;
92
- buf->ptr[buf->size] = '\0';
93
- }
94
- }
95
-
96
- void cmark_strbuf_sets(cmark_strbuf *buf, const char *string) {
97
- cmark_strbuf_set(buf, (const unsigned char *)string,
98
- string ? (bufsize_t)strlen(string) : 0);
99
- }
100
-
101
- void cmark_strbuf_putc(cmark_strbuf *buf, int c) {
102
- S_strbuf_grow_by(buf, 1);
103
- buf->ptr[buf->size++] = (unsigned char)(c & 0xFF);
104
- buf->ptr[buf->size] = '\0';
105
- }
106
-
107
- void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data,
108
- bufsize_t len) {
109
- if (len <= 0)
110
- return;
111
-
112
- S_strbuf_grow_by(buf, len);
113
- memmove(buf->ptr + buf->size, data, len);
114
- buf->size += len;
115
- buf->ptr[buf->size] = '\0';
116
- }
117
-
118
- void cmark_strbuf_puts(cmark_strbuf *buf, const char *string) {
119
- cmark_strbuf_put(buf, (const unsigned char *)string, (bufsize_t)strlen(string));
120
- }
121
-
122
- void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,
123
- const cmark_strbuf *buf) {
124
- bufsize_t copylen;
125
-
126
- assert(buf);
127
- if (!data || datasize <= 0)
128
- return;
129
-
130
- data[0] = '\0';
131
-
132
- if (buf->size == 0 || buf->asize <= 0)
133
- return;
134
-
135
- copylen = buf->size;
136
- if (copylen > datasize - 1)
137
- copylen = datasize - 1;
138
- memmove(data, buf->ptr, copylen);
139
- data[copylen] = '\0';
140
- }
141
-
142
- void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b) {
143
- cmark_strbuf t = *buf_a;
144
- *buf_a = *buf_b;
145
- *buf_b = t;
146
- }
147
-
148
- unsigned char *cmark_strbuf_detach(cmark_strbuf *buf) {
149
- unsigned char *data = buf->ptr;
150
-
151
- if (buf->asize == 0) {
152
- /* return an empty string */
153
- return (unsigned char *)buf->mem->calloc(1, 1);
154
- }
155
-
156
- cmark_strbuf_init(buf->mem, buf, 0);
157
- return data;
158
- }
159
-
160
- int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b) {
161
- int result = memcmp(a->ptr, b->ptr, MIN(a->size, b->size));
162
- return (result != 0) ? result
163
- : (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
164
- }
165
-
166
- bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos) {
167
- if (pos >= buf->size)
168
- return -1;
169
- if (pos < 0)
170
- pos = 0;
171
-
172
- const unsigned char *p =
173
- (unsigned char *)memchr(buf->ptr + pos, c, buf->size - pos);
174
- if (!p)
175
- return -1;
176
-
177
- return (bufsize_t)(p - (const unsigned char *)buf->ptr);
178
- }
179
-
180
- bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos) {
181
- if (pos < 0 || buf->size == 0)
182
- return -1;
183
- if (pos >= buf->size)
184
- pos = buf->size - 1;
185
-
186
- bufsize_t i;
187
- for (i = pos; i >= 0; i--) {
188
- if (buf->ptr[i] == (unsigned char)c)
189
- return i;
190
- }
191
-
192
- return -1;
193
- }
194
-
195
- void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len) {
196
- if (len < 0)
197
- len = 0;
198
-
199
- if (len < buf->size) {
200
- buf->size = len;
201
- buf->ptr[buf->size] = '\0';
202
- }
203
- }
204
-
205
- void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n) {
206
- if (n > 0) {
207
- if (n > buf->size)
208
- n = buf->size;
209
- buf->size = buf->size - n;
210
- if (buf->size)
211
- memmove(buf->ptr, buf->ptr + n, buf->size);
212
-
213
- buf->ptr[buf->size] = '\0';
214
- }
215
- }
216
-
217
- void cmark_strbuf_rtrim(cmark_strbuf *buf) {
218
- if (!buf->size)
219
- return;
220
-
221
- while (buf->size > 0) {
222
- if (!cmark_isspace(buf->ptr[buf->size - 1]))
223
- break;
224
-
225
- buf->size--;
226
- }
227
-
228
- buf->ptr[buf->size] = '\0';
229
- }
230
-
231
- void cmark_strbuf_trim(cmark_strbuf *buf) {
232
- bufsize_t i = 0;
233
-
234
- if (!buf->size)
235
- return;
236
-
237
- while (i < buf->size && cmark_isspace(buf->ptr[i]))
238
- i++;
239
-
240
- cmark_strbuf_drop(buf, i);
241
-
242
- cmark_strbuf_rtrim(buf);
243
- }
244
-
245
- // Destructively modify string, collapsing consecutive
246
- // space and newline characters into a single space.
247
- void cmark_strbuf_normalize_whitespace(cmark_strbuf *s) {
248
- bool last_char_was_space = false;
249
- bufsize_t r, w;
250
-
251
- for (r = 0, w = 0; r < s->size; ++r) {
252
- if (cmark_isspace(s->ptr[r])) {
253
- if (!last_char_was_space) {
254
- s->ptr[w++] = ' ';
255
- last_char_was_space = true;
256
- }
257
- } else {
258
- s->ptr[w++] = s->ptr[r];
259
- last_char_was_space = false;
260
- }
261
- }
262
-
263
- cmark_strbuf_truncate(s, w);
264
- }
265
-
266
- // Destructively unescape a string: remove backslashes before punctuation chars.
267
- extern void cmark_strbuf_unescape(cmark_strbuf *buf) {
268
- bufsize_t r, w;
269
-
270
- for (r = 0, w = 0; r < buf->size; ++r) {
271
- if (buf->ptr[r] == '\\' && cmark_ispunct(buf->ptr[r + 1]))
272
- r++;
273
-
274
- buf->ptr[w++] = buf->ptr[r];
275
- }
276
-
277
- cmark_strbuf_truncate(buf, w);
278
- }
@@ -1,116 +0,0 @@
1
- #ifndef CMARK_BUFFER_H
2
- #define CMARK_BUFFER_H
3
-
4
- #include <stddef.h>
5
- #include <stdarg.h>
6
- #include <string.h>
7
- #include <limits.h>
8
- #include <stdint.h>
9
- #include "config.h"
10
- #include "cmark-gfm.h"
11
-
12
- #ifdef __cplusplus
13
- extern "C" {
14
- #endif
15
-
16
- typedef struct {
17
- cmark_mem *mem;
18
- unsigned char *ptr;
19
- bufsize_t asize, size;
20
- } cmark_strbuf;
21
-
22
- extern unsigned char cmark_strbuf__initbuf[];
23
-
24
- #define CMARK_BUF_INIT(mem) \
25
- { mem, cmark_strbuf__initbuf, 0, 0 }
26
-
27
- /**
28
- * Initialize a cmark_strbuf structure.
29
- *
30
- * For the cases where CMARK_BUF_INIT cannot be used to do static
31
- * initialization.
32
- */
33
- CMARK_GFM_EXPORT
34
- void cmark_strbuf_init(cmark_mem *mem, cmark_strbuf *buf,
35
- bufsize_t initial_size);
36
-
37
- /**
38
- * Grow the buffer to hold at least `target_size` bytes.
39
- */
40
- CMARK_GFM_EXPORT
41
- void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size);
42
-
43
- CMARK_GFM_EXPORT
44
- void cmark_strbuf_free(cmark_strbuf *buf);
45
-
46
- CMARK_GFM_EXPORT
47
- void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b);
48
-
49
- CMARK_GFM_EXPORT
50
- bufsize_t cmark_strbuf_len(const cmark_strbuf *buf);
51
-
52
- CMARK_GFM_EXPORT
53
- int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b);
54
-
55
- CMARK_GFM_EXPORT
56
- unsigned char *cmark_strbuf_detach(cmark_strbuf *buf);
57
-
58
- CMARK_GFM_EXPORT
59
- void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,
60
- const cmark_strbuf *buf);
61
-
62
- static CMARK_INLINE const char *cmark_strbuf_cstr(const cmark_strbuf *buf) {
63
- return (char *)buf->ptr;
64
- }
65
-
66
- #define cmark_strbuf_at(buf, n) ((buf)->ptr[n])
67
-
68
- CMARK_GFM_EXPORT
69
- void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,
70
- bufsize_t len);
71
-
72
- CMARK_GFM_EXPORT
73
- void cmark_strbuf_sets(cmark_strbuf *buf, const char *string);
74
-
75
- CMARK_GFM_EXPORT
76
- void cmark_strbuf_putc(cmark_strbuf *buf, int c);
77
-
78
- CMARK_GFM_EXPORT
79
- void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data,
80
- bufsize_t len);
81
-
82
- CMARK_GFM_EXPORT
83
- void cmark_strbuf_puts(cmark_strbuf *buf, const char *string);
84
-
85
- CMARK_GFM_EXPORT
86
- void cmark_strbuf_clear(cmark_strbuf *buf);
87
-
88
- CMARK_GFM_EXPORT
89
- bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos);
90
-
91
- CMARK_GFM_EXPORT
92
- bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos);
93
-
94
- CMARK_GFM_EXPORT
95
- void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n);
96
-
97
- CMARK_GFM_EXPORT
98
- void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len);
99
-
100
- CMARK_GFM_EXPORT
101
- void cmark_strbuf_rtrim(cmark_strbuf *buf);
102
-
103
- CMARK_GFM_EXPORT
104
- void cmark_strbuf_trim(cmark_strbuf *buf);
105
-
106
- CMARK_GFM_EXPORT
107
- void cmark_strbuf_normalize_whitespace(cmark_strbuf *s);
108
-
109
- CMARK_GFM_EXPORT
110
- void cmark_strbuf_unescape(cmark_strbuf *s);
111
-
112
- #ifdef __cplusplus
113
- }
114
- #endif
115
-
116
- #endif