qiita_marker 0.23.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +50 -0
  4. data/Rakefile +113 -0
  5. data/bin/qiita_marker +123 -0
  6. data/ext/qiita_marker/arena.c +103 -0
  7. data/ext/qiita_marker/autolink.c +425 -0
  8. data/ext/qiita_marker/autolink.h +8 -0
  9. data/ext/qiita_marker/blocks.c +1596 -0
  10. data/ext/qiita_marker/buffer.c +278 -0
  11. data/ext/qiita_marker/buffer.h +116 -0
  12. data/ext/qiita_marker/case_fold_switch.inc +4327 -0
  13. data/ext/qiita_marker/chunk.h +135 -0
  14. data/ext/qiita_marker/cmark-gfm-core-extensions.h +54 -0
  15. data/ext/qiita_marker/cmark-gfm-extension_api.h +736 -0
  16. data/ext/qiita_marker/cmark-gfm-extensions_export.h +42 -0
  17. data/ext/qiita_marker/cmark-gfm.h +817 -0
  18. data/ext/qiita_marker/cmark-gfm_export.h +42 -0
  19. data/ext/qiita_marker/cmark-gfm_version.h +7 -0
  20. data/ext/qiita_marker/cmark.c +55 -0
  21. data/ext/qiita_marker/cmark_ctype.c +44 -0
  22. data/ext/qiita_marker/cmark_ctype.h +33 -0
  23. data/ext/qiita_marker/commonmark.c +529 -0
  24. data/ext/qiita_marker/config.h +76 -0
  25. data/ext/qiita_marker/core-extensions.c +27 -0
  26. data/ext/qiita_marker/entities.inc +2138 -0
  27. data/ext/qiita_marker/ext_scanners.c +879 -0
  28. data/ext/qiita_marker/ext_scanners.h +24 -0
  29. data/ext/qiita_marker/extconf.rb +7 -0
  30. data/ext/qiita_marker/footnotes.c +63 -0
  31. data/ext/qiita_marker/footnotes.h +27 -0
  32. data/ext/qiita_marker/houdini.h +57 -0
  33. data/ext/qiita_marker/houdini_href_e.c +100 -0
  34. data/ext/qiita_marker/houdini_html_e.c +66 -0
  35. data/ext/qiita_marker/houdini_html_u.c +149 -0
  36. data/ext/qiita_marker/html.c +486 -0
  37. data/ext/qiita_marker/html.h +27 -0
  38. data/ext/qiita_marker/inlines.c +1691 -0
  39. data/ext/qiita_marker/inlines.h +29 -0
  40. data/ext/qiita_marker/iterator.c +159 -0
  41. data/ext/qiita_marker/iterator.h +26 -0
  42. data/ext/qiita_marker/latex.c +466 -0
  43. data/ext/qiita_marker/linked_list.c +37 -0
  44. data/ext/qiita_marker/man.c +278 -0
  45. data/ext/qiita_marker/map.c +122 -0
  46. data/ext/qiita_marker/map.h +41 -0
  47. data/ext/qiita_marker/node.c +979 -0
  48. data/ext/qiita_marker/node.h +125 -0
  49. data/ext/qiita_marker/parser.h +58 -0
  50. data/ext/qiita_marker/plaintext.c +235 -0
  51. data/ext/qiita_marker/plugin.c +36 -0
  52. data/ext/qiita_marker/plugin.h +34 -0
  53. data/ext/qiita_marker/qiita_marker.c +1321 -0
  54. data/ext/qiita_marker/qiita_marker.h +16 -0
  55. data/ext/qiita_marker/references.c +42 -0
  56. data/ext/qiita_marker/references.h +26 -0
  57. data/ext/qiita_marker/registry.c +63 -0
  58. data/ext/qiita_marker/registry.h +24 -0
  59. data/ext/qiita_marker/render.c +205 -0
  60. data/ext/qiita_marker/render.h +62 -0
  61. data/ext/qiita_marker/scanners.c +10520 -0
  62. data/ext/qiita_marker/scanners.h +62 -0
  63. data/ext/qiita_marker/scanners.re +341 -0
  64. data/ext/qiita_marker/strikethrough.c +167 -0
  65. data/ext/qiita_marker/strikethrough.h +9 -0
  66. data/ext/qiita_marker/syntax_extension.c +149 -0
  67. data/ext/qiita_marker/syntax_extension.h +34 -0
  68. data/ext/qiita_marker/table.c +822 -0
  69. data/ext/qiita_marker/table.h +12 -0
  70. data/ext/qiita_marker/tagfilter.c +60 -0
  71. data/ext/qiita_marker/tagfilter.h +8 -0
  72. data/ext/qiita_marker/tasklist.c +156 -0
  73. data/ext/qiita_marker/tasklist.h +8 -0
  74. data/ext/qiita_marker/utf8.c +317 -0
  75. data/ext/qiita_marker/utf8.h +35 -0
  76. data/ext/qiita_marker/xml.c +181 -0
  77. data/lib/qiita_marker/config.rb +52 -0
  78. data/lib/qiita_marker/node/inspect.rb +57 -0
  79. data/lib/qiita_marker/node.rb +83 -0
  80. data/lib/qiita_marker/renderer/html_renderer.rb +252 -0
  81. data/lib/qiita_marker/renderer.rb +135 -0
  82. data/lib/qiita_marker/version.rb +5 -0
  83. data/lib/qiita_marker.rb +45 -0
  84. data/qiita_marker.gemspec +40 -0
  85. data/test/benchmark.rb +32 -0
  86. data/test/fixtures/curly.md +1 -0
  87. data/test/fixtures/dingus.md +10 -0
  88. data/test/fixtures/strong.md +1 -0
  89. data/test/fixtures/table.md +10 -0
  90. data/test/test_attributes.rb +24 -0
  91. data/test/test_basics.rb +35 -0
  92. data/test/test_commands.rb +72 -0
  93. data/test/test_commonmark.rb +36 -0
  94. data/test/test_doc.rb +130 -0
  95. data/test/test_encoding.rb +23 -0
  96. data/test/test_extensions.rb +116 -0
  97. data/test/test_footnotes.rb +60 -0
  98. data/test/test_gc.rb +47 -0
  99. data/test/test_helper.rb +71 -0
  100. data/test/test_linebreaks.rb +15 -0
  101. data/test/test_maliciousness.rb +262 -0
  102. data/test/test_node.rb +89 -0
  103. data/test/test_options.rb +37 -0
  104. data/test/test_pathological_inputs.rb +94 -0
  105. data/test/test_plaintext.rb +46 -0
  106. data/test/test_renderer.rb +47 -0
  107. data/test/test_smartpunct.rb +27 -0
  108. data/test/test_spec.rb +30 -0
  109. data/test/test_tasklists.rb +43 -0
  110. data/test/test_xml.rb +107 -0
  111. metadata +313 -0
@@ -0,0 +1,278 @@
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
+ }
@@ -0,0 +1,116 @@
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