commonmarker 0.23.10 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +1182 -0
  3. data/Cargo.toml +7 -0
  4. data/README.md +217 -170
  5. data/ext/commonmarker/Cargo.toml +20 -0
  6. data/ext/commonmarker/extconf.rb +3 -6
  7. data/ext/commonmarker/src/lib.rs +103 -0
  8. data/ext/commonmarker/src/node.rs +1151 -0
  9. data/ext/commonmarker/src/options.rs +175 -0
  10. data/ext/commonmarker/src/plugins/syntax_highlighting.rs +166 -0
  11. data/ext/commonmarker/src/plugins.rs +6 -0
  12. data/ext/commonmarker/src/utils.rs +8 -0
  13. data/lib/commonmarker/config.rb +92 -40
  14. data/lib/commonmarker/constants.rb +7 -0
  15. data/lib/commonmarker/extension.rb +14 -0
  16. data/lib/commonmarker/node/ast.rb +8 -0
  17. data/lib/commonmarker/node/inspect.rb +14 -4
  18. data/lib/commonmarker/node.rb +29 -47
  19. data/lib/commonmarker/renderer.rb +1 -127
  20. data/lib/commonmarker/utils.rb +22 -0
  21. data/lib/commonmarker/version.rb +2 -2
  22. data/lib/commonmarker.rb +27 -25
  23. metadata +38 -186
  24. data/Rakefile +0 -109
  25. data/bin/commonmarker +0 -118
  26. data/commonmarker.gemspec +0 -38
  27. data/ext/commonmarker/arena.c +0 -104
  28. data/ext/commonmarker/autolink.c +0 -508
  29. data/ext/commonmarker/autolink.h +0 -8
  30. data/ext/commonmarker/blocks.c +0 -1622
  31. data/ext/commonmarker/buffer.c +0 -278
  32. data/ext/commonmarker/buffer.h +0 -116
  33. data/ext/commonmarker/case_fold_switch.inc +0 -4327
  34. data/ext/commonmarker/chunk.h +0 -135
  35. data/ext/commonmarker/cmark-gfm-core-extensions.h +0 -54
  36. data/ext/commonmarker/cmark-gfm-extension_api.h +0 -737
  37. data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
  38. data/ext/commonmarker/cmark-gfm.h +0 -833
  39. data/ext/commonmarker/cmark-gfm_export.h +0 -42
  40. data/ext/commonmarker/cmark-gfm_version.h +0 -7
  41. data/ext/commonmarker/cmark.c +0 -55
  42. data/ext/commonmarker/cmark_ctype.c +0 -44
  43. data/ext/commonmarker/cmark_ctype.h +0 -33
  44. data/ext/commonmarker/commonmark.c +0 -514
  45. data/ext/commonmarker/commonmarker.c +0 -1308
  46. data/ext/commonmarker/commonmarker.h +0 -16
  47. data/ext/commonmarker/config.h +0 -76
  48. data/ext/commonmarker/core-extensions.c +0 -27
  49. data/ext/commonmarker/entities.inc +0 -2138
  50. data/ext/commonmarker/ext_scanners.c +0 -879
  51. data/ext/commonmarker/ext_scanners.h +0 -24
  52. data/ext/commonmarker/footnotes.c +0 -63
  53. data/ext/commonmarker/footnotes.h +0 -27
  54. data/ext/commonmarker/houdini.h +0 -57
  55. data/ext/commonmarker/houdini_href_e.c +0 -100
  56. data/ext/commonmarker/houdini_html_e.c +0 -66
  57. data/ext/commonmarker/houdini_html_u.c +0 -149
  58. data/ext/commonmarker/html.c +0 -502
  59. data/ext/commonmarker/html.h +0 -27
  60. data/ext/commonmarker/inlines.c +0 -1788
  61. data/ext/commonmarker/inlines.h +0 -29
  62. data/ext/commonmarker/iterator.c +0 -159
  63. data/ext/commonmarker/iterator.h +0 -26
  64. data/ext/commonmarker/latex.c +0 -468
  65. data/ext/commonmarker/linked_list.c +0 -37
  66. data/ext/commonmarker/man.c +0 -274
  67. data/ext/commonmarker/map.c +0 -129
  68. data/ext/commonmarker/map.h +0 -44
  69. data/ext/commonmarker/node.c +0 -1045
  70. data/ext/commonmarker/node.h +0 -167
  71. data/ext/commonmarker/parser.h +0 -59
  72. data/ext/commonmarker/plaintext.c +0 -218
  73. data/ext/commonmarker/plugin.c +0 -36
  74. data/ext/commonmarker/plugin.h +0 -34
  75. data/ext/commonmarker/references.c +0 -43
  76. data/ext/commonmarker/references.h +0 -26
  77. data/ext/commonmarker/registry.c +0 -63
  78. data/ext/commonmarker/registry.h +0 -24
  79. data/ext/commonmarker/render.c +0 -213
  80. data/ext/commonmarker/render.h +0 -62
  81. data/ext/commonmarker/scanners.c +0 -14056
  82. data/ext/commonmarker/scanners.h +0 -70
  83. data/ext/commonmarker/scanners.re +0 -341
  84. data/ext/commonmarker/strikethrough.c +0 -167
  85. data/ext/commonmarker/strikethrough.h +0 -9
  86. data/ext/commonmarker/syntax_extension.c +0 -149
  87. data/ext/commonmarker/syntax_extension.h +0 -34
  88. data/ext/commonmarker/table.c +0 -917
  89. data/ext/commonmarker/table.h +0 -12
  90. data/ext/commonmarker/tagfilter.c +0 -60
  91. data/ext/commonmarker/tagfilter.h +0 -8
  92. data/ext/commonmarker/tasklist.c +0 -156
  93. data/ext/commonmarker/tasklist.h +0 -8
  94. data/ext/commonmarker/utf8.c +0 -317
  95. data/ext/commonmarker/utf8.h +0 -35
  96. data/ext/commonmarker/xml.c +0 -182
  97. data/lib/commonmarker/renderer/html_renderer.rb +0 -256
@@ -1,213 +0,0 @@
1
- #include <stdlib.h>
2
- #include "buffer.h"
3
- #include "chunk.h"
4
- #include "cmark-gfm.h"
5
- #include "utf8.h"
6
- #include "render.h"
7
- #include "node.h"
8
- #include "syntax_extension.h"
9
-
10
- static CMARK_INLINE void S_cr(cmark_renderer *renderer) {
11
- if (renderer->need_cr < 1) {
12
- renderer->need_cr = 1;
13
- }
14
- }
15
-
16
- static CMARK_INLINE void S_blankline(cmark_renderer *renderer) {
17
- if (renderer->need_cr < 2) {
18
- renderer->need_cr = 2;
19
- }
20
- }
21
-
22
- static void S_out(cmark_renderer *renderer, cmark_node *node,
23
- const char *source, bool wrap,
24
- cmark_escaping escape) {
25
- int length = (int)strlen(source);
26
- unsigned char nextc;
27
- int32_t c;
28
- int i = 0;
29
- int last_nonspace;
30
- int len;
31
- cmark_chunk remainder = cmark_chunk_literal("");
32
- int k = renderer->buffer->size - 1;
33
-
34
- cmark_syntax_extension *ext = node->ancestor_extension;
35
- if (ext && !ext->commonmark_escape_func)
36
- ext = NULL;
37
-
38
- wrap = wrap && !renderer->no_linebreaks;
39
-
40
- if (renderer->in_tight_list_item && renderer->need_cr > 1) {
41
- renderer->need_cr = 1;
42
- }
43
- while (renderer->need_cr) {
44
- if (k < 0 || renderer->buffer->ptr[k] == '\n') {
45
- k -= 1;
46
- } else {
47
- cmark_strbuf_putc(renderer->buffer, '\n');
48
- if (renderer->need_cr > 1) {
49
- cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
50
- renderer->prefix->size);
51
- }
52
- }
53
- renderer->column = 0;
54
- renderer->last_breakable = 0;
55
- renderer->begin_line = true;
56
- renderer->begin_content = true;
57
- renderer->need_cr -= 1;
58
- }
59
-
60
- while (i < length) {
61
- if (renderer->begin_line) {
62
- cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
63
- renderer->prefix->size);
64
- // note: this assumes prefix is ascii:
65
- renderer->column = renderer->prefix->size;
66
- }
67
-
68
- len = cmark_utf8proc_iterate((const uint8_t *)source + i, length - i, &c);
69
- if (len == -1) { // error condition
70
- return; // return without rendering rest of string
71
- }
72
-
73
- if (ext && ext->commonmark_escape_func(ext, node, c))
74
- cmark_strbuf_putc(renderer->buffer, '\\');
75
-
76
- nextc = source[i + len];
77
- if (c == 32 && wrap) {
78
- if (!renderer->begin_line) {
79
- last_nonspace = renderer->buffer->size;
80
- cmark_strbuf_putc(renderer->buffer, ' ');
81
- renderer->column += 1;
82
- renderer->begin_line = false;
83
- renderer->begin_content = false;
84
- // skip following spaces
85
- while (source[i + 1] == ' ') {
86
- i++;
87
- }
88
- // We don't allow breaks that make a digit the first character
89
- // because this causes problems with commonmark output.
90
- if (!cmark_isdigit(source[i + 1])) {
91
- renderer->last_breakable = last_nonspace;
92
- }
93
- }
94
-
95
- } else if (escape == LITERAL) {
96
- if (c == 10) {
97
- cmark_strbuf_putc(renderer->buffer, '\n');
98
- renderer->column = 0;
99
- renderer->begin_line = true;
100
- renderer->begin_content = true;
101
- renderer->last_breakable = 0;
102
- } else {
103
- cmark_render_code_point(renderer, c);
104
- renderer->begin_line = false;
105
- // we don't set 'begin_content' to false til we've
106
- // finished parsing a digit. Reason: in commonmark
107
- // we need to escape a potential list marker after
108
- // a digit:
109
- renderer->begin_content =
110
- renderer->begin_content && cmark_isdigit((char)c) == 1;
111
- }
112
- } else {
113
- (renderer->outc)(renderer, node, escape, c, nextc);
114
- renderer->begin_line = false;
115
- renderer->begin_content =
116
- renderer->begin_content && cmark_isdigit((char)c) == 1;
117
- }
118
-
119
- // If adding the character went beyond width, look for an
120
- // earlier place where the line could be broken:
121
- if (renderer->width > 0 && renderer->column > renderer->width &&
122
- !renderer->begin_line && renderer->last_breakable > 0) {
123
-
124
- // copy from last_breakable to remainder
125
- cmark_chunk_set_cstr(renderer->mem, &remainder,
126
- (char *)renderer->buffer->ptr +
127
- renderer->last_breakable + 1);
128
- // truncate at last_breakable
129
- cmark_strbuf_truncate(renderer->buffer, renderer->last_breakable);
130
- // add newline, prefix, and remainder
131
- cmark_strbuf_putc(renderer->buffer, '\n');
132
- cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
133
- renderer->prefix->size);
134
- cmark_strbuf_put(renderer->buffer, remainder.data, remainder.len);
135
- renderer->column = renderer->prefix->size + remainder.len;
136
- cmark_chunk_free(renderer->mem, &remainder);
137
- renderer->last_breakable = 0;
138
- renderer->begin_line = false;
139
- renderer->begin_content = false;
140
- }
141
-
142
- i += len;
143
- }
144
- }
145
-
146
- // Assumes no newlines, assumes ascii content:
147
- void cmark_render_ascii(cmark_renderer *renderer, const char *s) {
148
- int origsize = renderer->buffer->size;
149
- cmark_strbuf_puts(renderer->buffer, s);
150
- renderer->column += renderer->buffer->size - origsize;
151
- }
152
-
153
- void cmark_render_code_point(cmark_renderer *renderer, uint32_t c) {
154
- cmark_utf8proc_encode_char(c, renderer->buffer);
155
- renderer->column += 1;
156
- }
157
-
158
- char *cmark_render(cmark_mem *mem, cmark_node *root, int options, int width,
159
- void (*outc)(cmark_renderer *, cmark_node *,
160
- cmark_escaping, int32_t,
161
- unsigned char),
162
- int (*render_node)(cmark_renderer *renderer,
163
- cmark_node *node,
164
- cmark_event_type ev_type, int options)) {
165
- cmark_strbuf pref = CMARK_BUF_INIT(mem);
166
- cmark_strbuf buf = CMARK_BUF_INIT(mem);
167
- cmark_node *cur;
168
- cmark_event_type ev_type;
169
- char *result;
170
- cmark_iter *iter = cmark_iter_new(root);
171
-
172
- cmark_renderer renderer = {mem, &buf, &pref, 0, width,
173
- 0, 0, true, true, false,
174
- false, outc, S_cr, S_blankline, S_out,
175
- 0};
176
-
177
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
178
- cur = cmark_iter_get_node(iter);
179
- if (cur->extension) {
180
- cur->ancestor_extension = cur->extension;
181
- } else if (cur->parent) {
182
- cur->ancestor_extension = cur->parent->ancestor_extension;
183
- }
184
- if (cur->type == CMARK_NODE_ITEM) {
185
- // Calculate the list item's index, for the benefit of output formats
186
- // like commonmark and plaintext.
187
- if (cur->prev) {
188
- cmark_node_set_item_index(cur, 1 + cmark_node_get_item_index(cur->prev));
189
- } else {
190
- cmark_node_set_item_index(cur, cmark_node_get_list_start(cur->parent));
191
- }
192
- }
193
- if (!render_node(&renderer, cur, ev_type, options)) {
194
- // a false value causes us to skip processing
195
- // the node's contents. this is used for
196
- // autolinks.
197
- cmark_iter_reset(iter, cur, CMARK_EVENT_EXIT);
198
- }
199
- }
200
-
201
- // ensure final newline
202
- if (renderer.buffer->size == 0 || renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
203
- cmark_strbuf_putc(renderer.buffer, '\n');
204
- }
205
-
206
- result = (char *)cmark_strbuf_detach(renderer.buffer);
207
-
208
- cmark_iter_free(iter);
209
- cmark_strbuf_free(renderer.prefix);
210
- cmark_strbuf_free(renderer.buffer);
211
-
212
- return result;
213
- }
@@ -1,62 +0,0 @@
1
- #ifndef CMARK_RENDER_H
2
- #define CMARK_RENDER_H
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- #include <stdlib.h>
9
- #include "buffer.h"
10
- #include "chunk.h"
11
-
12
- typedef enum { LITERAL, NORMAL, TITLE, URL } cmark_escaping;
13
-
14
- struct cmark_renderer {
15
- cmark_mem *mem;
16
- cmark_strbuf *buffer;
17
- cmark_strbuf *prefix;
18
- int column;
19
- int width;
20
- int need_cr;
21
- bufsize_t last_breakable;
22
- bool begin_line;
23
- bool begin_content;
24
- bool no_linebreaks;
25
- bool in_tight_list_item;
26
- void (*outc)(struct cmark_renderer *, cmark_node *, cmark_escaping, int32_t, unsigned char);
27
- void (*cr)(struct cmark_renderer *);
28
- void (*blankline)(struct cmark_renderer *);
29
- void (*out)(struct cmark_renderer *, cmark_node *, const char *, bool, cmark_escaping);
30
- unsigned int footnote_ix;
31
- };
32
-
33
- typedef struct cmark_renderer cmark_renderer;
34
-
35
- struct cmark_html_renderer {
36
- cmark_strbuf *html;
37
- cmark_node *plain;
38
- cmark_llist *filter_extensions;
39
- unsigned int footnote_ix;
40
- unsigned int written_footnote_ix;
41
- void *opaque;
42
- };
43
-
44
- typedef struct cmark_html_renderer cmark_html_renderer;
45
-
46
- void cmark_render_ascii(cmark_renderer *renderer, const char *s);
47
-
48
- void cmark_render_code_point(cmark_renderer *renderer, uint32_t c);
49
-
50
- char *cmark_render(cmark_mem *mem, cmark_node *root, int options, int width,
51
- void (*outc)(cmark_renderer *, cmark_node *,
52
- cmark_escaping, int32_t,
53
- unsigned char),
54
- int (*render_node)(cmark_renderer *renderer,
55
- cmark_node *node,
56
- cmark_event_type ev_type, int options));
57
-
58
- #ifdef __cplusplus
59
- }
60
- #endif
61
-
62
- #endif