commonmarker 0.23.10 → 1.1.3

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 +1220 -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 +183 -0
  8. data/ext/commonmarker/src/node.rs +1112 -0
  9. data/ext/commonmarker/src/options.rs +165 -0
  10. data/ext/commonmarker/src/plugins/syntax_highlighting.rs +74 -0
  11. data/ext/commonmarker/src/plugins.rs +3 -0
  12. data/ext/commonmarker/src/utils.rs +8 -0
  13. data/lib/commonmarker/config.rb +90 -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,167 +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
- // Extensions can register custom flags by calling `cmark_register_node_flag`.
57
- // This is the starting value for the custom flags.
58
- CMARK_NODE__REGISTER_FIRST = (1 << 3),
59
- };
60
-
61
- typedef uint16_t cmark_node_internal_flags;
62
-
63
- struct cmark_node {
64
- cmark_strbuf content;
65
-
66
- struct cmark_node *next;
67
- struct cmark_node *prev;
68
- struct cmark_node *parent;
69
- struct cmark_node *first_child;
70
- struct cmark_node *last_child;
71
-
72
- void *user_data;
73
- cmark_free_func user_data_free_func;
74
-
75
- int start_line;
76
- int start_column;
77
- int end_line;
78
- int end_column;
79
- int internal_offset;
80
- uint16_t type;
81
- cmark_node_internal_flags flags;
82
-
83
- cmark_syntax_extension *extension;
84
-
85
- /**
86
- * Used during cmark_render() to cache the most recent non-NULL
87
- * extension, if you go up the parent chain like this:
88
- *
89
- * node->parent->...parent->extension
90
- */
91
- cmark_syntax_extension *ancestor_extension;
92
-
93
- union {
94
- int ref_ix;
95
- int def_count;
96
- } footnote;
97
-
98
- cmark_node *parent_footnote_def;
99
-
100
- union {
101
- cmark_chunk literal;
102
- cmark_list list;
103
- cmark_code code;
104
- cmark_heading heading;
105
- cmark_link link;
106
- cmark_custom custom;
107
- int html_block_type;
108
- int cell_index; // For keeping track of TABLE_CELL table alignments
109
- void *opaque;
110
- } as;
111
- };
112
-
113
- /**
114
- * Syntax extensions can use this function to register a custom node
115
- * flag. The flags are stored in the `flags` field of the `cmark_node`
116
- * struct. The `flags` parameter should be the address of a global variable
117
- * which will store the flag value.
118
- */
119
- CMARK_GFM_EXPORT
120
- void cmark_register_node_flag(cmark_node_internal_flags *flags);
121
-
122
- /**
123
- * DEPRECATED.
124
- *
125
- * This function was added in cmark-gfm version 0.29.0.gfm.7, and was
126
- * required to be called at program start time, which caused
127
- * backwards-compatibility issues in applications that use cmark-gfm as a
128
- * library. It is now a no-op.
129
- */
130
- CMARK_GFM_EXPORT
131
- void cmark_init_standard_node_flags(void);
132
-
133
- static CMARK_INLINE cmark_mem *cmark_node_mem(cmark_node *node) {
134
- return node->content.mem;
135
- }
136
- CMARK_GFM_EXPORT int cmark_node_check(cmark_node *node, FILE *out);
137
-
138
- static CMARK_INLINE bool CMARK_NODE_TYPE_BLOCK_P(cmark_node_type node_type) {
139
- return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_BLOCK;
140
- }
141
-
142
- static CMARK_INLINE bool CMARK_NODE_BLOCK_P(cmark_node *node) {
143
- return node != NULL && CMARK_NODE_TYPE_BLOCK_P((cmark_node_type) node->type);
144
- }
145
-
146
- static CMARK_INLINE bool CMARK_NODE_TYPE_INLINE_P(cmark_node_type node_type) {
147
- return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_INLINE;
148
- }
149
-
150
- static CMARK_INLINE bool CMARK_NODE_INLINE_P(cmark_node *node) {
151
- return node != NULL && CMARK_NODE_TYPE_INLINE_P((cmark_node_type) node->type);
152
- }
153
-
154
- CMARK_GFM_EXPORT bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type);
155
-
156
- /**
157
- * Enable (or disable) extra safety checks. These extra checks cause
158
- * extra performance overhead (in some cases quadratic), so they are only
159
- * intended to be used during testing.
160
- */
161
- CMARK_GFM_EXPORT void cmark_enable_safety_checks(bool enable);
162
-
163
- #ifdef __cplusplus
164
- }
165
- #endif
166
-
167
- #endif
@@ -1,59 +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
- size_t total_size;
50
- cmark_llist *syntax_extensions;
51
- cmark_llist *inline_syntax_extensions;
52
- cmark_ispunct_func backslash_ispunct;
53
- };
54
-
55
- #ifdef __cplusplus
56
- }
57
- #endif
58
-
59
- #endif
@@ -1,218 +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
- static int S_render_node(cmark_renderer *renderer, cmark_node *node,
20
- cmark_event_type ev_type, int options) {
21
- int list_number;
22
- cmark_delim_type list_delim;
23
- int i;
24
- bool entering = (ev_type == CMARK_EVENT_ENTER);
25
- char listmarker[LISTMARKER_SIZE];
26
- bool first_in_list_item;
27
- bufsize_t marker_width;
28
- bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options) &&
29
- !(CMARK_OPT_HARDBREAKS & options);
30
-
31
- // Don't adjust tight list status til we've started the list.
32
- // Otherwise we loose the blank line between a paragraph and
33
- // a following list.
34
- if (entering) {
35
- if (node->parent && node->parent->type == CMARK_NODE_ITEM) {
36
- renderer->in_tight_list_item = node->parent->parent->as.list.tight;
37
- }
38
- } else {
39
- if (node->type == CMARK_NODE_LIST) {
40
- renderer->in_tight_list_item =
41
- node->parent &&
42
- node->parent->type == CMARK_NODE_ITEM &&
43
- node->parent->parent->as.list.tight;
44
- }
45
- }
46
-
47
- if (node->extension && node->extension->plaintext_render_func) {
48
- node->extension->plaintext_render_func(node->extension, renderer, node, ev_type, options);
49
- return 1;
50
- }
51
-
52
- switch (node->type) {
53
- case CMARK_NODE_DOCUMENT:
54
- break;
55
-
56
- case CMARK_NODE_BLOCK_QUOTE:
57
- break;
58
-
59
- case CMARK_NODE_LIST:
60
- if (!entering && node->next && (node->next->type == CMARK_NODE_CODE_BLOCK ||
61
- node->next->type == CMARK_NODE_LIST)) {
62
- CR();
63
- }
64
- break;
65
-
66
- case CMARK_NODE_ITEM:
67
- if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
68
- marker_width = 4;
69
- } else {
70
- list_number = cmark_node_get_item_index(node);
71
- list_delim = cmark_node_get_list_delim(node->parent);
72
- // we ensure a width of at least 4 so
73
- // we get nice transition from single digits
74
- // to double
75
- snprintf(listmarker, LISTMARKER_SIZE, "%d%s%s", list_number,
76
- list_delim == CMARK_PAREN_DELIM ? ")" : ".",
77
- list_number < 10 ? " " : " ");
78
- marker_width = (bufsize_t)strlen(listmarker);
79
- }
80
- if (entering) {
81
- if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
82
- LIT(" - ");
83
- renderer->begin_content = true;
84
- } else {
85
- LIT(listmarker);
86
- renderer->begin_content = true;
87
- }
88
- for (i = marker_width; i--;) {
89
- cmark_strbuf_putc(renderer->prefix, ' ');
90
- }
91
- } else {
92
- cmark_strbuf_truncate(renderer->prefix,
93
- renderer->prefix->size - marker_width);
94
- CR();
95
- }
96
- break;
97
-
98
- case CMARK_NODE_HEADING:
99
- if (entering) {
100
- renderer->begin_content = true;
101
- renderer->no_linebreaks = true;
102
- } else {
103
- renderer->no_linebreaks = false;
104
- BLANKLINE();
105
- }
106
- break;
107
-
108
- case CMARK_NODE_CODE_BLOCK:
109
- first_in_list_item = node->prev == NULL && node->parent &&
110
- node->parent->type == CMARK_NODE_ITEM;
111
-
112
- if (!first_in_list_item) {
113
- BLANKLINE();
114
- }
115
- OUT(cmark_node_get_literal(node), false, LITERAL);
116
- BLANKLINE();
117
- break;
118
-
119
- case CMARK_NODE_HTML_BLOCK:
120
- break;
121
-
122
- case CMARK_NODE_CUSTOM_BLOCK:
123
- break;
124
-
125
- case CMARK_NODE_THEMATIC_BREAK:
126
- BLANKLINE();
127
- break;
128
-
129
- case CMARK_NODE_PARAGRAPH:
130
- if (!entering) {
131
- BLANKLINE();
132
- }
133
- break;
134
-
135
- case CMARK_NODE_TEXT:
136
- OUT(cmark_node_get_literal(node), allow_wrap, NORMAL);
137
- break;
138
-
139
- case CMARK_NODE_LINEBREAK:
140
- CR();
141
- break;
142
-
143
- case CMARK_NODE_SOFTBREAK:
144
- if (CMARK_OPT_HARDBREAKS & options) {
145
- CR();
146
- } else if (!renderer->no_linebreaks && renderer->width == 0 &&
147
- !(CMARK_OPT_HARDBREAKS & options) &&
148
- !(CMARK_OPT_NOBREAKS & options)) {
149
- CR();
150
- } else {
151
- OUT(" ", allow_wrap, LITERAL);
152
- }
153
- break;
154
-
155
- case CMARK_NODE_CODE:
156
- OUT(cmark_node_get_literal(node), allow_wrap, LITERAL);
157
- break;
158
-
159
- case CMARK_NODE_HTML_INLINE:
160
- break;
161
-
162
- case CMARK_NODE_CUSTOM_INLINE:
163
- break;
164
-
165
- case CMARK_NODE_STRONG:
166
- break;
167
-
168
- case CMARK_NODE_EMPH:
169
- break;
170
-
171
- case CMARK_NODE_LINK:
172
- break;
173
-
174
- case CMARK_NODE_IMAGE:
175
- break;
176
-
177
- case CMARK_NODE_FOOTNOTE_REFERENCE:
178
- if (entering) {
179
- LIT("[^");
180
- OUT(cmark_chunk_to_cstr(renderer->mem, &node->as.literal), false, LITERAL);
181
- LIT("]");
182
- }
183
- break;
184
-
185
- case CMARK_NODE_FOOTNOTE_DEFINITION:
186
- if (entering) {
187
- renderer->footnote_ix += 1;
188
- LIT("[^");
189
- char n[32];
190
- snprintf(n, sizeof(n), "%d", renderer->footnote_ix);
191
- OUT(n, false, LITERAL);
192
- LIT("]: ");
193
-
194
- cmark_strbuf_puts(renderer->prefix, " ");
195
- } else {
196
- cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 4);
197
- }
198
- break;
199
- default:
200
- assert(false);
201
- break;
202
- }
203
-
204
- return 1;
205
- }
206
-
207
- char *cmark_render_plaintext(cmark_node *root, int options, int width) {
208
- return cmark_render_plaintext_with_mem(root, options, width, cmark_node_mem(root));
209
- }
210
-
211
- char *cmark_render_plaintext_with_mem(cmark_node *root, int options, int width, cmark_mem *mem) {
212
- if (options & CMARK_OPT_HARDBREAKS) {
213
- // disable breaking on width, since it has
214
- // a different meaning with OPT_HARDBREAKS
215
- width = 0;
216
- }
217
- return cmark_render(mem, root, options, width, outc, S_render_node);
218
- }
@@ -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,43 +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
- ref->entry.size = ref->url.len + ref->title.len;
36
-
37
- map->refs = (cmark_map_entry *)ref;
38
- map->size++;
39
- }
40
-
41
- cmark_map *cmark_reference_map_new(cmark_mem *mem) {
42
- return cmark_map_new(mem, reference_free);
43
- }
@@ -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