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,125 +0,0 @@
1
- #ifndef CMARK_NODE_H
2
- #define CMARK_NODE_H
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- #include <stdio.h>
9
- #include <stdint.h>
10
-
11
- #include "cmark-gfm.h"
12
- #include "cmark-gfm-extension_api.h"
13
- #include "buffer.h"
14
- #include "chunk.h"
15
-
16
- typedef struct {
17
- cmark_list_type list_type;
18
- int marker_offset;
19
- int padding;
20
- int start;
21
- cmark_delim_type delimiter;
22
- unsigned char bullet_char;
23
- bool tight;
24
- bool checked; // For task list extension
25
- } cmark_list;
26
-
27
- typedef struct {
28
- cmark_chunk info;
29
- cmark_chunk literal;
30
- uint8_t fence_length;
31
- uint8_t fence_offset;
32
- unsigned char fence_char;
33
- int8_t fenced;
34
- } cmark_code;
35
-
36
- typedef struct {
37
- int level;
38
- bool setext;
39
- } cmark_heading;
40
-
41
- typedef struct {
42
- cmark_chunk url;
43
- cmark_chunk title;
44
- } cmark_link;
45
-
46
- typedef struct {
47
- cmark_chunk on_enter;
48
- cmark_chunk on_exit;
49
- } cmark_custom;
50
-
51
- enum cmark_node__internal_flags {
52
- CMARK_NODE__OPEN = (1 << 0),
53
- CMARK_NODE__LAST_LINE_BLANK = (1 << 1),
54
- CMARK_NODE__LAST_LINE_CHECKED = (1 << 2),
55
- };
56
-
57
- struct cmark_node {
58
- cmark_strbuf content;
59
-
60
- struct cmark_node *next;
61
- struct cmark_node *prev;
62
- struct cmark_node *parent;
63
- struct cmark_node *first_child;
64
- struct cmark_node *last_child;
65
-
66
- void *user_data;
67
- cmark_free_func user_data_free_func;
68
-
69
- int start_line;
70
- int start_column;
71
- int end_line;
72
- int end_column;
73
- int internal_offset;
74
- uint16_t type;
75
- uint16_t flags;
76
-
77
- cmark_syntax_extension *extension;
78
-
79
- union {
80
- int ref_ix;
81
- int def_count;
82
- } footnote;
83
-
84
- cmark_node *parent_footnote_def;
85
-
86
- union {
87
- cmark_chunk literal;
88
- cmark_list list;
89
- cmark_code code;
90
- cmark_heading heading;
91
- cmark_link link;
92
- cmark_custom custom;
93
- int html_block_type;
94
- void *opaque;
95
- } as;
96
- };
97
-
98
- static CMARK_INLINE cmark_mem *cmark_node_mem(cmark_node *node) {
99
- return node->content.mem;
100
- }
101
- CMARK_GFM_EXPORT int cmark_node_check(cmark_node *node, FILE *out);
102
-
103
- static CMARK_INLINE bool CMARK_NODE_TYPE_BLOCK_P(cmark_node_type node_type) {
104
- return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_BLOCK;
105
- }
106
-
107
- static CMARK_INLINE bool CMARK_NODE_BLOCK_P(cmark_node *node) {
108
- return node != NULL && CMARK_NODE_TYPE_BLOCK_P((cmark_node_type) node->type);
109
- }
110
-
111
- static CMARK_INLINE bool CMARK_NODE_TYPE_INLINE_P(cmark_node_type node_type) {
112
- return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_INLINE;
113
- }
114
-
115
- static CMARK_INLINE bool CMARK_NODE_INLINE_P(cmark_node *node) {
116
- return node != NULL && CMARK_NODE_TYPE_INLINE_P((cmark_node_type) node->type);
117
- }
118
-
119
- CMARK_GFM_EXPORT bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type);
120
-
121
- #ifdef __cplusplus
122
- }
123
- #endif
124
-
125
- #endif
@@ -1,58 +0,0 @@
1
- #ifndef CMARK_PARSER_H
2
- #define CMARK_PARSER_H
3
-
4
- #include <stdio.h>
5
- #include "references.h"
6
- #include "node.h"
7
- #include "buffer.h"
8
-
9
- #ifdef __cplusplus
10
- extern "C" {
11
- #endif
12
-
13
- #define MAX_LINK_LABEL_LENGTH 1000
14
-
15
- struct cmark_parser {
16
- struct cmark_mem *mem;
17
- /* A hashtable of urls in the current document for cross-references */
18
- struct cmark_map *refmap;
19
- /* The root node of the parser, always a CMARK_NODE_DOCUMENT */
20
- struct cmark_node *root;
21
- /* The last open block after a line is fully processed */
22
- struct cmark_node *current;
23
- /* See the documentation for cmark_parser_get_line_number() in cmark.h */
24
- int line_number;
25
- /* See the documentation for cmark_parser_get_offset() in cmark.h */
26
- bufsize_t offset;
27
- /* See the documentation for cmark_parser_get_column() in cmark.h */
28
- bufsize_t column;
29
- /* See the documentation for cmark_parser_get_first_nonspace() in cmark.h */
30
- bufsize_t first_nonspace;
31
- /* See the documentation for cmark_parser_get_first_nonspace_column() in cmark.h */
32
- bufsize_t first_nonspace_column;
33
- bufsize_t thematic_break_kill_pos;
34
- /* See the documentation for cmark_parser_get_indent() in cmark.h */
35
- int indent;
36
- /* See the documentation for cmark_parser_is_blank() in cmark.h */
37
- bool blank;
38
- /* See the documentation for cmark_parser_has_partially_consumed_tab() in cmark.h */
39
- bool partially_consumed_tab;
40
- /* Contains the currently processed line */
41
- cmark_strbuf curline;
42
- /* See the documentation for cmark_parser_get_last_line_length() in cmark.h */
43
- bufsize_t last_line_length;
44
- /* FIXME: not sure about the difference with curline */
45
- cmark_strbuf linebuf;
46
- /* Options set by the user, see the Options section in cmark.h */
47
- int options;
48
- bool last_buffer_ended_with_cr;
49
- cmark_llist *syntax_extensions;
50
- cmark_llist *inline_syntax_extensions;
51
- cmark_ispunct_func backslash_ispunct;
52
- };
53
-
54
- #ifdef __cplusplus
55
- }
56
- #endif
57
-
58
- #endif
@@ -1,235 +0,0 @@
1
- #include "node.h"
2
- #include "syntax_extension.h"
3
- #include "render.h"
4
-
5
- #define OUT(s, wrap, escaping) renderer->out(renderer, node, s, wrap, escaping)
6
- #define LIT(s) renderer->out(renderer, node, s, false, LITERAL)
7
- #define CR() renderer->cr(renderer)
8
- #define BLANKLINE() renderer->blankline(renderer)
9
- #define LISTMARKER_SIZE 20
10
-
11
- // Functions to convert cmark_nodes to plain text strings.
12
-
13
- static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_node *node,
14
- cmark_escaping escape,
15
- int32_t c, unsigned char nextc) {
16
- cmark_render_code_point(renderer, c);
17
- }
18
-
19
- // if node is a block node, returns node.
20
- // otherwise returns first block-level node that is an ancestor of node.
21
- // if there is no block-level ancestor, returns NULL.
22
- static cmark_node *get_containing_block(cmark_node *node) {
23
- while (node) {
24
- if (CMARK_NODE_BLOCK_P(node)) {
25
- return node;
26
- } else {
27
- node = node->parent;
28
- }
29
- }
30
- return NULL;
31
- }
32
-
33
- static int S_render_node(cmark_renderer *renderer, cmark_node *node,
34
- cmark_event_type ev_type, int options) {
35
- cmark_node *tmp;
36
- int list_number;
37
- cmark_delim_type list_delim;
38
- int i;
39
- bool entering = (ev_type == CMARK_EVENT_ENTER);
40
- char listmarker[LISTMARKER_SIZE];
41
- bool first_in_list_item;
42
- bufsize_t marker_width;
43
- bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options) &&
44
- !(CMARK_OPT_HARDBREAKS & options);
45
-
46
- // Don't adjust tight list status til we've started the list.
47
- // Otherwise we loose the blank line between a paragraph and
48
- // a following list.
49
- if (!(node->type == CMARK_NODE_ITEM && node->prev == NULL && entering)) {
50
- tmp = get_containing_block(node);
51
- renderer->in_tight_list_item =
52
- tmp && // tmp might be NULL if there is no containing block
53
- ((tmp->type == CMARK_NODE_ITEM &&
54
- cmark_node_get_list_tight(tmp->parent)) ||
55
- (tmp && tmp->parent && tmp->parent->type == CMARK_NODE_ITEM &&
56
- cmark_node_get_list_tight(tmp->parent->parent)));
57
- }
58
-
59
- if (node->extension && node->extension->plaintext_render_func) {
60
- node->extension->plaintext_render_func(node->extension, renderer, node, ev_type, options);
61
- return 1;
62
- }
63
-
64
- switch (node->type) {
65
- case CMARK_NODE_DOCUMENT:
66
- break;
67
-
68
- case CMARK_NODE_BLOCK_QUOTE:
69
- break;
70
-
71
- case CMARK_NODE_LIST:
72
- if (!entering && node->next && (node->next->type == CMARK_NODE_CODE_BLOCK ||
73
- node->next->type == CMARK_NODE_LIST)) {
74
- CR();
75
- }
76
- break;
77
-
78
- case CMARK_NODE_ITEM:
79
- if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
80
- marker_width = 4;
81
- } else {
82
- list_number = cmark_node_get_list_start(node->parent);
83
- list_delim = cmark_node_get_list_delim(node->parent);
84
- tmp = node;
85
- while (tmp->prev) {
86
- tmp = tmp->prev;
87
- list_number += 1;
88
- }
89
- // we ensure a width of at least 4 so
90
- // we get nice transition from single digits
91
- // to double
92
- snprintf(listmarker, LISTMARKER_SIZE, "%d%s%s", list_number,
93
- list_delim == CMARK_PAREN_DELIM ? ")" : ".",
94
- list_number < 10 ? " " : " ");
95
- marker_width = (bufsize_t)strlen(listmarker);
96
- }
97
- if (entering) {
98
- if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
99
- LIT(" - ");
100
- renderer->begin_content = true;
101
- } else {
102
- LIT(listmarker);
103
- renderer->begin_content = true;
104
- }
105
- for (i = marker_width; i--;) {
106
- cmark_strbuf_putc(renderer->prefix, ' ');
107
- }
108
- } else {
109
- cmark_strbuf_truncate(renderer->prefix,
110
- renderer->prefix->size - marker_width);
111
- CR();
112
- }
113
- break;
114
-
115
- case CMARK_NODE_HEADING:
116
- if (entering) {
117
- renderer->begin_content = true;
118
- renderer->no_linebreaks = true;
119
- } else {
120
- renderer->no_linebreaks = false;
121
- BLANKLINE();
122
- }
123
- break;
124
-
125
- case CMARK_NODE_CODE_BLOCK:
126
- first_in_list_item = node->prev == NULL && node->parent &&
127
- node->parent->type == CMARK_NODE_ITEM;
128
-
129
- if (!first_in_list_item) {
130
- BLANKLINE();
131
- }
132
- OUT(cmark_node_get_literal(node), false, LITERAL);
133
- BLANKLINE();
134
- break;
135
-
136
- case CMARK_NODE_HTML_BLOCK:
137
- break;
138
-
139
- case CMARK_NODE_CUSTOM_BLOCK:
140
- break;
141
-
142
- case CMARK_NODE_THEMATIC_BREAK:
143
- BLANKLINE();
144
- break;
145
-
146
- case CMARK_NODE_PARAGRAPH:
147
- if (!entering) {
148
- BLANKLINE();
149
- }
150
- break;
151
-
152
- case CMARK_NODE_TEXT:
153
- OUT(cmark_node_get_literal(node), allow_wrap, NORMAL);
154
- break;
155
-
156
- case CMARK_NODE_LINEBREAK:
157
- CR();
158
- break;
159
-
160
- case CMARK_NODE_SOFTBREAK:
161
- if (CMARK_OPT_HARDBREAKS & options) {
162
- CR();
163
- } else if (!renderer->no_linebreaks && renderer->width == 0 &&
164
- !(CMARK_OPT_HARDBREAKS & options) &&
165
- !(CMARK_OPT_NOBREAKS & options)) {
166
- CR();
167
- } else {
168
- OUT(" ", allow_wrap, LITERAL);
169
- }
170
- break;
171
-
172
- case CMARK_NODE_CODE:
173
- OUT(cmark_node_get_literal(node), allow_wrap, LITERAL);
174
- break;
175
-
176
- case CMARK_NODE_HTML_INLINE:
177
- break;
178
-
179
- case CMARK_NODE_CUSTOM_INLINE:
180
- break;
181
-
182
- case CMARK_NODE_STRONG:
183
- break;
184
-
185
- case CMARK_NODE_EMPH:
186
- break;
187
-
188
- case CMARK_NODE_LINK:
189
- break;
190
-
191
- case CMARK_NODE_IMAGE:
192
- break;
193
-
194
- case CMARK_NODE_FOOTNOTE_REFERENCE:
195
- if (entering) {
196
- LIT("[^");
197
- OUT(cmark_chunk_to_cstr(renderer->mem, &node->as.literal), false, LITERAL);
198
- LIT("]");
199
- }
200
- break;
201
-
202
- case CMARK_NODE_FOOTNOTE_DEFINITION:
203
- if (entering) {
204
- renderer->footnote_ix += 1;
205
- LIT("[^");
206
- char n[32];
207
- snprintf(n, sizeof(n), "%d", renderer->footnote_ix);
208
- OUT(n, false, LITERAL);
209
- LIT("]: ");
210
-
211
- cmark_strbuf_puts(renderer->prefix, " ");
212
- } else {
213
- cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 4);
214
- }
215
- break;
216
- default:
217
- assert(false);
218
- break;
219
- }
220
-
221
- return 1;
222
- }
223
-
224
- char *cmark_render_plaintext(cmark_node *root, int options, int width) {
225
- return cmark_render_plaintext_with_mem(root, options, width, cmark_node_mem(root));
226
- }
227
-
228
- char *cmark_render_plaintext_with_mem(cmark_node *root, int options, int width, cmark_mem *mem) {
229
- if (options & CMARK_OPT_HARDBREAKS) {
230
- // disable breaking on width, since it has
231
- // a different meaning with OPT_HARDBREAKS
232
- width = 0;
233
- }
234
- return cmark_render(mem, root, options, width, outc, S_render_node);
235
- }
@@ -1,36 +0,0 @@
1
- #include <stdlib.h>
2
-
3
- #include "plugin.h"
4
-
5
- extern cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR;
6
-
7
- int cmark_plugin_register_syntax_extension(cmark_plugin * plugin,
8
- cmark_syntax_extension * extension) {
9
- plugin->syntax_extensions = cmark_llist_append(&CMARK_DEFAULT_MEM_ALLOCATOR, plugin->syntax_extensions, extension);
10
- return 1;
11
- }
12
-
13
- cmark_plugin *
14
- cmark_plugin_new(void) {
15
- cmark_plugin *res = (cmark_plugin *) CMARK_DEFAULT_MEM_ALLOCATOR.calloc(1, sizeof(cmark_plugin));
16
-
17
- res->syntax_extensions = NULL;
18
-
19
- return res;
20
- }
21
-
22
- void
23
- cmark_plugin_free(cmark_plugin *plugin) {
24
- cmark_llist_free_full(&CMARK_DEFAULT_MEM_ALLOCATOR,
25
- plugin->syntax_extensions,
26
- (cmark_free_func) cmark_syntax_extension_free);
27
- CMARK_DEFAULT_MEM_ALLOCATOR.free(plugin);
28
- }
29
-
30
- cmark_llist *
31
- cmark_plugin_steal_syntax_extensions(cmark_plugin *plugin) {
32
- cmark_llist *res = plugin->syntax_extensions;
33
-
34
- plugin->syntax_extensions = NULL;
35
- return res;
36
- }
@@ -1,34 +0,0 @@
1
- #ifndef CMARK_PLUGIN_H
2
- #define CMARK_PLUGIN_H
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- #include "cmark-gfm.h"
9
- #include "cmark-gfm-extension_api.h"
10
-
11
- /**
12
- * cmark_plugin:
13
- *
14
- * A plugin structure, which should be filled by plugin's
15
- * init functions.
16
- */
17
- struct cmark_plugin {
18
- cmark_llist *syntax_extensions;
19
- };
20
-
21
- cmark_llist *
22
- cmark_plugin_steal_syntax_extensions(cmark_plugin *plugin);
23
-
24
- cmark_plugin *
25
- cmark_plugin_new(void);
26
-
27
- void
28
- cmark_plugin_free(cmark_plugin *plugin);
29
-
30
- #ifdef __cplusplus
31
- }
32
- #endif
33
-
34
- #endif
@@ -1,42 +0,0 @@
1
- #include "cmark-gfm.h"
2
- #include "parser.h"
3
- #include "references.h"
4
- #include "inlines.h"
5
- #include "chunk.h"
6
-
7
- static void reference_free(cmark_map *map, cmark_map_entry *_ref) {
8
- cmark_reference *ref = (cmark_reference *)_ref;
9
- cmark_mem *mem = map->mem;
10
- if (ref != NULL) {
11
- mem->free(ref->entry.label);
12
- cmark_chunk_free(mem, &ref->url);
13
- cmark_chunk_free(mem, &ref->title);
14
- mem->free(ref);
15
- }
16
- }
17
-
18
- void cmark_reference_create(cmark_map *map, cmark_chunk *label,
19
- cmark_chunk *url, cmark_chunk *title) {
20
- cmark_reference *ref;
21
- unsigned char *reflabel = normalize_map_label(map->mem, label);
22
-
23
- /* empty reference name, or composed from only whitespace */
24
- if (reflabel == NULL)
25
- return;
26
-
27
- assert(map->sorted == NULL);
28
-
29
- ref = (cmark_reference *)map->mem->calloc(1, sizeof(*ref));
30
- ref->entry.label = reflabel;
31
- ref->url = cmark_clean_url(map->mem, url);
32
- ref->title = cmark_clean_title(map->mem, title);
33
- ref->entry.age = map->size;
34
- ref->entry.next = map->refs;
35
-
36
- map->refs = (cmark_map_entry *)ref;
37
- map->size++;
38
- }
39
-
40
- cmark_map *cmark_reference_map_new(cmark_mem *mem) {
41
- return cmark_map_new(mem, reference_free);
42
- }
@@ -1,26 +0,0 @@
1
- #ifndef CMARK_REFERENCES_H
2
- #define CMARK_REFERENCES_H
3
-
4
- #include "map.h"
5
-
6
- #ifdef __cplusplus
7
- extern "C" {
8
- #endif
9
-
10
- struct cmark_reference {
11
- cmark_map_entry entry;
12
- cmark_chunk url;
13
- cmark_chunk title;
14
- };
15
-
16
- typedef struct cmark_reference cmark_reference;
17
-
18
- void cmark_reference_create(cmark_map *map, cmark_chunk *label,
19
- cmark_chunk *url, cmark_chunk *title);
20
- cmark_map *cmark_reference_map_new(cmark_mem *mem);
21
-
22
- #ifdef __cplusplus
23
- }
24
- #endif
25
-
26
- #endif
@@ -1,63 +0,0 @@
1
- #include <stdint.h>
2
- #include <stdlib.h>
3
- #include <string.h>
4
-
5
- #include "config.h"
6
- #include "cmark-gfm.h"
7
- #include "syntax_extension.h"
8
- #include "registry.h"
9
- #include "plugin.h"
10
-
11
- extern cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR;
12
-
13
- static cmark_llist *syntax_extensions = NULL;
14
-
15
- void cmark_register_plugin(cmark_plugin_init_func reg_fn) {
16
- cmark_plugin *plugin = cmark_plugin_new();
17
-
18
- if (!reg_fn(plugin)) {
19
- cmark_plugin_free(plugin);
20
- return;
21
- }
22
-
23
- cmark_llist *syntax_extensions_list = cmark_plugin_steal_syntax_extensions(plugin),
24
- *it;
25
-
26
- for (it = syntax_extensions_list; it; it = it->next) {
27
- syntax_extensions = cmark_llist_append(&CMARK_DEFAULT_MEM_ALLOCATOR, syntax_extensions, it->data);
28
- }
29
-
30
- cmark_llist_free(&CMARK_DEFAULT_MEM_ALLOCATOR, syntax_extensions_list);
31
- cmark_plugin_free(plugin);
32
- }
33
-
34
- void cmark_release_plugins(void) {
35
- if (syntax_extensions) {
36
- cmark_llist_free_full(
37
- &CMARK_DEFAULT_MEM_ALLOCATOR,
38
- syntax_extensions,
39
- (cmark_free_func) cmark_syntax_extension_free);
40
- syntax_extensions = NULL;
41
- }
42
- }
43
-
44
- cmark_llist *cmark_list_syntax_extensions(cmark_mem *mem) {
45
- cmark_llist *it;
46
- cmark_llist *res = NULL;
47
-
48
- for (it = syntax_extensions; it; it = it->next) {
49
- res = cmark_llist_append(mem, res, it->data);
50
- }
51
- return res;
52
- }
53
-
54
- cmark_syntax_extension *cmark_find_syntax_extension(const char *name) {
55
- cmark_llist *tmp;
56
-
57
- for (tmp = syntax_extensions; tmp; tmp = tmp->next) {
58
- cmark_syntax_extension *ext = (cmark_syntax_extension *) tmp->data;
59
- if (!strcmp(ext->name, name))
60
- return ext;
61
- }
62
- return NULL;
63
- }
@@ -1,24 +0,0 @@
1
- #ifndef CMARK_REGISTRY_H
2
- #define CMARK_REGISTRY_H
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- #include "cmark-gfm.h"
9
- #include "plugin.h"
10
-
11
- CMARK_GFM_EXPORT
12
- void cmark_register_plugin(cmark_plugin_init_func reg_fn);
13
-
14
- CMARK_GFM_EXPORT
15
- void cmark_release_plugins(void);
16
-
17
- CMARK_GFM_EXPORT
18
- cmark_llist *cmark_list_syntax_extensions(cmark_mem *mem);
19
-
20
- #ifdef __cplusplus
21
- }
22
- #endif
23
-
24
- #endif