commonmarker 0.23.10 → 1.1.1

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 +1095 -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,833 +0,0 @@
1
- #ifndef CMARK_GFM_H
2
- #define CMARK_GFM_H
3
-
4
- #include <stdio.h>
5
- #include <stdint.h>
6
- #include "cmark-gfm_export.h"
7
- #include "cmark-gfm_version.h"
8
-
9
- #ifdef __cplusplus
10
- extern "C" {
11
- #endif
12
-
13
- /** # NAME
14
- *
15
- * **cmark-gfm** - CommonMark parsing, manipulating, and rendering
16
- */
17
-
18
- /** # DESCRIPTION
19
- *
20
- * ## Simple Interface
21
- */
22
-
23
- /** Convert 'text' (assumed to be a UTF-8 encoded string with length
24
- * 'len') from CommonMark Markdown to HTML, returning a null-terminated,
25
- * UTF-8-encoded string. It is the caller's responsibility
26
- * to free the returned buffer.
27
- */
28
- CMARK_GFM_EXPORT
29
- char *cmark_markdown_to_html(const char *text, size_t len, int options);
30
-
31
- /** ## Node Structure
32
- */
33
-
34
- #define CMARK_NODE_TYPE_PRESENT (0x8000)
35
- #define CMARK_NODE_TYPE_BLOCK (CMARK_NODE_TYPE_PRESENT | 0x0000)
36
- #define CMARK_NODE_TYPE_INLINE (CMARK_NODE_TYPE_PRESENT | 0x4000)
37
- #define CMARK_NODE_TYPE_MASK (0xc000)
38
- #define CMARK_NODE_VALUE_MASK (0x3fff)
39
-
40
- typedef enum {
41
- /* Error status */
42
- CMARK_NODE_NONE = 0x0000,
43
-
44
- /* Block */
45
- CMARK_NODE_DOCUMENT = CMARK_NODE_TYPE_BLOCK | 0x0001,
46
- CMARK_NODE_BLOCK_QUOTE = CMARK_NODE_TYPE_BLOCK | 0x0002,
47
- CMARK_NODE_LIST = CMARK_NODE_TYPE_BLOCK | 0x0003,
48
- CMARK_NODE_ITEM = CMARK_NODE_TYPE_BLOCK | 0x0004,
49
- CMARK_NODE_CODE_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0005,
50
- CMARK_NODE_HTML_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0006,
51
- CMARK_NODE_CUSTOM_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0007,
52
- CMARK_NODE_PARAGRAPH = CMARK_NODE_TYPE_BLOCK | 0x0008,
53
- CMARK_NODE_HEADING = CMARK_NODE_TYPE_BLOCK | 0x0009,
54
- CMARK_NODE_THEMATIC_BREAK = CMARK_NODE_TYPE_BLOCK | 0x000a,
55
- CMARK_NODE_FOOTNOTE_DEFINITION = CMARK_NODE_TYPE_BLOCK | 0x000b,
56
-
57
- /* Inline */
58
- CMARK_NODE_TEXT = CMARK_NODE_TYPE_INLINE | 0x0001,
59
- CMARK_NODE_SOFTBREAK = CMARK_NODE_TYPE_INLINE | 0x0002,
60
- CMARK_NODE_LINEBREAK = CMARK_NODE_TYPE_INLINE | 0x0003,
61
- CMARK_NODE_CODE = CMARK_NODE_TYPE_INLINE | 0x0004,
62
- CMARK_NODE_HTML_INLINE = CMARK_NODE_TYPE_INLINE | 0x0005,
63
- CMARK_NODE_CUSTOM_INLINE = CMARK_NODE_TYPE_INLINE | 0x0006,
64
- CMARK_NODE_EMPH = CMARK_NODE_TYPE_INLINE | 0x0007,
65
- CMARK_NODE_STRONG = CMARK_NODE_TYPE_INLINE | 0x0008,
66
- CMARK_NODE_LINK = CMARK_NODE_TYPE_INLINE | 0x0009,
67
- CMARK_NODE_IMAGE = CMARK_NODE_TYPE_INLINE | 0x000a,
68
- CMARK_NODE_FOOTNOTE_REFERENCE = CMARK_NODE_TYPE_INLINE | 0x000b,
69
- } cmark_node_type;
70
-
71
- extern cmark_node_type CMARK_NODE_LAST_BLOCK;
72
- extern cmark_node_type CMARK_NODE_LAST_INLINE;
73
-
74
- /* For backwards compatibility: */
75
- #define CMARK_NODE_HEADER CMARK_NODE_HEADING
76
- #define CMARK_NODE_HRULE CMARK_NODE_THEMATIC_BREAK
77
- #define CMARK_NODE_HTML CMARK_NODE_HTML_BLOCK
78
- #define CMARK_NODE_INLINE_HTML CMARK_NODE_HTML_INLINE
79
-
80
- typedef enum {
81
- CMARK_NO_LIST,
82
- CMARK_BULLET_LIST,
83
- CMARK_ORDERED_LIST
84
- } cmark_list_type;
85
-
86
- typedef enum {
87
- CMARK_NO_DELIM,
88
- CMARK_PERIOD_DELIM,
89
- CMARK_PAREN_DELIM
90
- } cmark_delim_type;
91
-
92
- typedef struct cmark_node cmark_node;
93
- typedef struct cmark_parser cmark_parser;
94
- typedef struct cmark_iter cmark_iter;
95
- typedef struct cmark_syntax_extension cmark_syntax_extension;
96
-
97
- /**
98
- * ## Custom memory allocator support
99
- */
100
-
101
- /** Defines the memory allocation functions to be used by CMark
102
- * when parsing and allocating a document tree
103
- */
104
- typedef struct cmark_mem {
105
- void *(*calloc)(size_t, size_t);
106
- void *(*realloc)(void *, size_t);
107
- void (*free)(void *);
108
- } cmark_mem;
109
-
110
- /** The default memory allocator; uses the system's calloc,
111
- * realloc and free.
112
- */
113
- CMARK_GFM_EXPORT
114
- cmark_mem *cmark_get_default_mem_allocator(void);
115
-
116
- /** An arena allocator; uses system calloc to allocate large
117
- * slabs of memory. Memory in these slabs is not reused at all.
118
- */
119
- CMARK_GFM_EXPORT
120
- cmark_mem *cmark_get_arena_mem_allocator(void);
121
-
122
- /** Resets the arena allocator, quickly returning all used memory
123
- * to the operating system.
124
- */
125
- CMARK_GFM_EXPORT
126
- void cmark_arena_reset(void);
127
-
128
- /** Callback for freeing user data with a 'cmark_mem' context.
129
- */
130
- typedef void (*cmark_free_func) (cmark_mem *mem, void *user_data);
131
-
132
-
133
- /*
134
- * ## Basic data structures
135
- *
136
- * To keep dependencies to the strict minimum, libcmark implements
137
- * its own versions of "classic" data structures.
138
- */
139
-
140
- /**
141
- * ### Linked list
142
- */
143
-
144
- /** A generic singly linked list.
145
- */
146
- typedef struct _cmark_llist
147
- {
148
- struct _cmark_llist *next;
149
- void *data;
150
- } cmark_llist;
151
-
152
- /** Append an element to the linked list, return the possibly modified
153
- * head of the list.
154
- */
155
- CMARK_GFM_EXPORT
156
- cmark_llist * cmark_llist_append (cmark_mem * mem,
157
- cmark_llist * head,
158
- void * data);
159
-
160
- /** Free the list starting with 'head', calling 'free_func' with the
161
- * data pointer of each of its elements
162
- */
163
- CMARK_GFM_EXPORT
164
- void cmark_llist_free_full (cmark_mem * mem,
165
- cmark_llist * head,
166
- cmark_free_func free_func);
167
-
168
- /** Free the list starting with 'head'
169
- */
170
- CMARK_GFM_EXPORT
171
- void cmark_llist_free (cmark_mem * mem,
172
- cmark_llist * head);
173
-
174
- /**
175
- * ## Creating and Destroying Nodes
176
- */
177
-
178
- /** Creates a new node of type 'type'. Note that the node may have
179
- * other required properties, which it is the caller's responsibility
180
- * to assign.
181
- */
182
- CMARK_GFM_EXPORT cmark_node *cmark_node_new(cmark_node_type type);
183
-
184
- /** Same as `cmark_node_new`, but explicitly listing the memory
185
- * allocator used to allocate the node. Note: be sure to use the same
186
- * allocator for every node in a tree, or bad things can happen.
187
- */
188
- CMARK_GFM_EXPORT cmark_node *cmark_node_new_with_mem(cmark_node_type type,
189
- cmark_mem *mem);
190
-
191
- CMARK_GFM_EXPORT cmark_node *cmark_node_new_with_ext(cmark_node_type type,
192
- cmark_syntax_extension *extension);
193
-
194
- CMARK_GFM_EXPORT cmark_node *cmark_node_new_with_mem_and_ext(cmark_node_type type,
195
- cmark_mem *mem,
196
- cmark_syntax_extension *extension);
197
-
198
- /** Frees the memory allocated for a node and any children.
199
- */
200
- CMARK_GFM_EXPORT void cmark_node_free(cmark_node *node);
201
-
202
- /**
203
- * ## Tree Traversal
204
- */
205
-
206
- /** Returns the next node in the sequence after 'node', or NULL if
207
- * there is none.
208
- */
209
- CMARK_GFM_EXPORT cmark_node *cmark_node_next(cmark_node *node);
210
-
211
- /** Returns the previous node in the sequence after 'node', or NULL if
212
- * there is none.
213
- */
214
- CMARK_GFM_EXPORT cmark_node *cmark_node_previous(cmark_node *node);
215
-
216
- /** Returns the parent of 'node', or NULL if there is none.
217
- */
218
- CMARK_GFM_EXPORT cmark_node *cmark_node_parent(cmark_node *node);
219
-
220
- /** Returns the first child of 'node', or NULL if 'node' has no children.
221
- */
222
- CMARK_GFM_EXPORT cmark_node *cmark_node_first_child(cmark_node *node);
223
-
224
- /** Returns the last child of 'node', or NULL if 'node' has no children.
225
- */
226
- CMARK_GFM_EXPORT cmark_node *cmark_node_last_child(cmark_node *node);
227
-
228
- /** Returns the footnote reference of 'node', or NULL if 'node' doesn't have a
229
- * footnote reference.
230
- */
231
- CMARK_GFM_EXPORT cmark_node *cmark_node_parent_footnote_def(cmark_node *node);
232
-
233
- /**
234
- * ## Iterator
235
- *
236
- * An iterator will walk through a tree of nodes, starting from a root
237
- * node, returning one node at a time, together with information about
238
- * whether the node is being entered or exited. The iterator will
239
- * first descend to a child node, if there is one. When there is no
240
- * child, the iterator will go to the next sibling. When there is no
241
- * next sibling, the iterator will return to the parent (but with
242
- * a 'cmark_event_type' of `CMARK_EVENT_EXIT`). The iterator will
243
- * return `CMARK_EVENT_DONE` when it reaches the root node again.
244
- * One natural application is an HTML renderer, where an `ENTER` event
245
- * outputs an open tag and an `EXIT` event outputs a close tag.
246
- * An iterator might also be used to transform an AST in some systematic
247
- * way, for example, turning all level-3 headings into regular paragraphs.
248
- *
249
- * void
250
- * usage_example(cmark_node *root) {
251
- * cmark_event_type ev_type;
252
- * cmark_iter *iter = cmark_iter_new(root);
253
- *
254
- * while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
255
- * cmark_node *cur = cmark_iter_get_node(iter);
256
- * // Do something with `cur` and `ev_type`
257
- * }
258
- *
259
- * cmark_iter_free(iter);
260
- * }
261
- *
262
- * Iterators will never return `EXIT` events for leaf nodes, which are nodes
263
- * of type:
264
- *
265
- * * CMARK_NODE_HTML_BLOCK
266
- * * CMARK_NODE_THEMATIC_BREAK
267
- * * CMARK_NODE_CODE_BLOCK
268
- * * CMARK_NODE_TEXT
269
- * * CMARK_NODE_SOFTBREAK
270
- * * CMARK_NODE_LINEBREAK
271
- * * CMARK_NODE_CODE
272
- * * CMARK_NODE_HTML_INLINE
273
- *
274
- * Nodes must only be modified after an `EXIT` event, or an `ENTER` event for
275
- * leaf nodes.
276
- */
277
-
278
- typedef enum {
279
- CMARK_EVENT_NONE,
280
- CMARK_EVENT_DONE,
281
- CMARK_EVENT_ENTER,
282
- CMARK_EVENT_EXIT
283
- } cmark_event_type;
284
-
285
- /** Creates a new iterator starting at 'root'. The current node and event
286
- * type are undefined until 'cmark_iter_next' is called for the first time.
287
- * The memory allocated for the iterator should be released using
288
- * 'cmark_iter_free' when it is no longer needed.
289
- */
290
- CMARK_GFM_EXPORT
291
- cmark_iter *cmark_iter_new(cmark_node *root);
292
-
293
- /** Frees the memory allocated for an iterator.
294
- */
295
- CMARK_GFM_EXPORT
296
- void cmark_iter_free(cmark_iter *iter);
297
-
298
- /** Advances to the next node and returns the event type (`CMARK_EVENT_ENTER`,
299
- * `CMARK_EVENT_EXIT` or `CMARK_EVENT_DONE`).
300
- */
301
- CMARK_GFM_EXPORT
302
- cmark_event_type cmark_iter_next(cmark_iter *iter);
303
-
304
- /** Returns the current node.
305
- */
306
- CMARK_GFM_EXPORT
307
- cmark_node *cmark_iter_get_node(cmark_iter *iter);
308
-
309
- /** Returns the current event type.
310
- */
311
- CMARK_GFM_EXPORT
312
- cmark_event_type cmark_iter_get_event_type(cmark_iter *iter);
313
-
314
- /** Returns the root node.
315
- */
316
- CMARK_GFM_EXPORT
317
- cmark_node *cmark_iter_get_root(cmark_iter *iter);
318
-
319
- /** Resets the iterator so that the current node is 'current' and
320
- * the event type is 'event_type'. The new current node must be a
321
- * descendant of the root node or the root node itself.
322
- */
323
- CMARK_GFM_EXPORT
324
- void cmark_iter_reset(cmark_iter *iter, cmark_node *current,
325
- cmark_event_type event_type);
326
-
327
- /**
328
- * ## Accessors
329
- */
330
-
331
- /** Returns the user data of 'node'.
332
- */
333
- CMARK_GFM_EXPORT void *cmark_node_get_user_data(cmark_node *node);
334
-
335
- /** Sets arbitrary user data for 'node'. Returns 1 on success,
336
- * 0 on failure.
337
- */
338
- CMARK_GFM_EXPORT int cmark_node_set_user_data(cmark_node *node, void *user_data);
339
-
340
- /** Set free function for user data */
341
- CMARK_GFM_EXPORT
342
- int cmark_node_set_user_data_free_func(cmark_node *node,
343
- cmark_free_func free_func);
344
-
345
- /** Returns the type of 'node', or `CMARK_NODE_NONE` on error.
346
- */
347
- CMARK_GFM_EXPORT cmark_node_type cmark_node_get_type(cmark_node *node);
348
-
349
- /** Like 'cmark_node_get_type', but returns a string representation
350
- of the type, or `"<unknown>"`.
351
- */
352
- CMARK_GFM_EXPORT
353
- const char *cmark_node_get_type_string(cmark_node *node);
354
-
355
- /** Returns the string contents of 'node', or an empty
356
- string if none is set. Returns NULL if called on a
357
- node that does not have string content.
358
- */
359
- CMARK_GFM_EXPORT const char *cmark_node_get_literal(cmark_node *node);
360
-
361
- /** Sets the string contents of 'node'. Returns 1 on success,
362
- * 0 on failure.
363
- */
364
- CMARK_GFM_EXPORT int cmark_node_set_literal(cmark_node *node, const char *content);
365
-
366
- /** Returns the heading level of 'node', or 0 if 'node' is not a heading.
367
- */
368
- CMARK_GFM_EXPORT int cmark_node_get_heading_level(cmark_node *node);
369
-
370
- /* For backwards compatibility */
371
- #define cmark_node_get_header_level cmark_node_get_heading_level
372
- #define cmark_node_set_header_level cmark_node_set_heading_level
373
-
374
- /** Sets the heading level of 'node', returning 1 on success and 0 on error.
375
- */
376
- CMARK_GFM_EXPORT int cmark_node_set_heading_level(cmark_node *node, int level);
377
-
378
- /** Returns the list type of 'node', or `CMARK_NO_LIST` if 'node'
379
- * is not a list.
380
- */
381
- CMARK_GFM_EXPORT cmark_list_type cmark_node_get_list_type(cmark_node *node);
382
-
383
- /** Sets the list type of 'node', returning 1 on success and 0 on error.
384
- */
385
- CMARK_GFM_EXPORT int cmark_node_set_list_type(cmark_node *node,
386
- cmark_list_type type);
387
-
388
- /** Returns the list delimiter type of 'node', or `CMARK_NO_DELIM` if 'node'
389
- * is not a list.
390
- */
391
- CMARK_GFM_EXPORT cmark_delim_type cmark_node_get_list_delim(cmark_node *node);
392
-
393
- /** Sets the list delimiter type of 'node', returning 1 on success and 0
394
- * on error.
395
- */
396
- CMARK_GFM_EXPORT int cmark_node_set_list_delim(cmark_node *node,
397
- cmark_delim_type delim);
398
-
399
- /** Returns starting number of 'node', if it is an ordered list, otherwise 0.
400
- */
401
- CMARK_GFM_EXPORT int cmark_node_get_list_start(cmark_node *node);
402
-
403
- /** Sets starting number of 'node', if it is an ordered list. Returns 1
404
- * on success, 0 on failure.
405
- */
406
- CMARK_GFM_EXPORT int cmark_node_set_list_start(cmark_node *node, int start);
407
-
408
- /** Returns 1 if 'node' is a tight list, 0 otherwise.
409
- */
410
- CMARK_GFM_EXPORT int cmark_node_get_list_tight(cmark_node *node);
411
-
412
- /** Sets the "tightness" of a list. Returns 1 on success, 0 on failure.
413
- */
414
- CMARK_GFM_EXPORT int cmark_node_set_list_tight(cmark_node *node, int tight);
415
-
416
- /**
417
- * Returns item index of 'node'. This is only used when rendering output
418
- * formats such as commonmark, which need to output the index. It is not
419
- * required for formats such as html or latex.
420
- */
421
- CMARK_GFM_EXPORT int cmark_node_get_item_index(cmark_node *node);
422
-
423
- /** Sets item index of 'node'. Returns 1 on success, 0 on failure.
424
- */
425
- CMARK_GFM_EXPORT int cmark_node_set_item_index(cmark_node *node, int idx);
426
-
427
- /** Returns the info string from a fenced code block.
428
- */
429
- CMARK_GFM_EXPORT const char *cmark_node_get_fence_info(cmark_node *node);
430
-
431
- /** Sets the info string in a fenced code block, returning 1 on
432
- * success and 0 on failure.
433
- */
434
- CMARK_GFM_EXPORT int cmark_node_set_fence_info(cmark_node *node, const char *info);
435
-
436
- /** Sets code blocks fencing details
437
- */
438
- CMARK_GFM_EXPORT int cmark_node_set_fenced(cmark_node * node, int fenced,
439
- int length, int offset, char character);
440
-
441
- /** Returns code blocks fencing details
442
- */
443
- CMARK_GFM_EXPORT int cmark_node_get_fenced(cmark_node *node, int *length, int *offset, char *character);
444
-
445
- /** Returns the URL of a link or image 'node', or an empty string
446
- if no URL is set. Returns NULL if called on a node that is
447
- not a link or image.
448
- */
449
- CMARK_GFM_EXPORT const char *cmark_node_get_url(cmark_node *node);
450
-
451
- /** Sets the URL of a link or image 'node'. Returns 1 on success,
452
- * 0 on failure.
453
- */
454
- CMARK_GFM_EXPORT int cmark_node_set_url(cmark_node *node, const char *url);
455
-
456
- /** Returns the title of a link or image 'node', or an empty
457
- string if no title is set. Returns NULL if called on a node
458
- that is not a link or image.
459
- */
460
- CMARK_GFM_EXPORT const char *cmark_node_get_title(cmark_node *node);
461
-
462
- /** Sets the title of a link or image 'node'. Returns 1 on success,
463
- * 0 on failure.
464
- */
465
- CMARK_GFM_EXPORT int cmark_node_set_title(cmark_node *node, const char *title);
466
-
467
- /** Returns the literal "on enter" text for a custom 'node', or
468
- an empty string if no on_enter is set. Returns NULL if called
469
- on a non-custom node.
470
- */
471
- CMARK_GFM_EXPORT const char *cmark_node_get_on_enter(cmark_node *node);
472
-
473
- /** Sets the literal text to render "on enter" for a custom 'node'.
474
- Any children of the node will be rendered after this text.
475
- Returns 1 on success 0 on failure.
476
- */
477
- CMARK_GFM_EXPORT int cmark_node_set_on_enter(cmark_node *node,
478
- const char *on_enter);
479
-
480
- /** Returns the literal "on exit" text for a custom 'node', or
481
- an empty string if no on_exit is set. Returns NULL if
482
- called on a non-custom node.
483
- */
484
- CMARK_GFM_EXPORT const char *cmark_node_get_on_exit(cmark_node *node);
485
-
486
- /** Sets the literal text to render "on exit" for a custom 'node'.
487
- Any children of the node will be rendered before this text.
488
- Returns 1 on success 0 on failure.
489
- */
490
- CMARK_GFM_EXPORT int cmark_node_set_on_exit(cmark_node *node, const char *on_exit);
491
-
492
- /** Returns the line on which 'node' begins.
493
- */
494
- CMARK_GFM_EXPORT int cmark_node_get_start_line(cmark_node *node);
495
-
496
- /** Returns the column at which 'node' begins.
497
- */
498
- CMARK_GFM_EXPORT int cmark_node_get_start_column(cmark_node *node);
499
-
500
- /** Returns the line on which 'node' ends.
501
- */
502
- CMARK_GFM_EXPORT int cmark_node_get_end_line(cmark_node *node);
503
-
504
- /** Returns the column at which 'node' ends.
505
- */
506
- CMARK_GFM_EXPORT int cmark_node_get_end_column(cmark_node *node);
507
-
508
- /**
509
- * ## Tree Manipulation
510
- */
511
-
512
- /** Unlinks a 'node', removing it from the tree, but not freeing its
513
- * memory. (Use 'cmark_node_free' for that.)
514
- */
515
- CMARK_GFM_EXPORT void cmark_node_unlink(cmark_node *node);
516
-
517
- /** Inserts 'sibling' before 'node'. Returns 1 on success, 0 on failure.
518
- */
519
- CMARK_GFM_EXPORT int cmark_node_insert_before(cmark_node *node,
520
- cmark_node *sibling);
521
-
522
- /** Inserts 'sibling' after 'node'. Returns 1 on success, 0 on failure.
523
- */
524
- CMARK_GFM_EXPORT int cmark_node_insert_after(cmark_node *node, cmark_node *sibling);
525
-
526
- /** Replaces 'oldnode' with 'newnode' and unlinks 'oldnode' (but does
527
- * not free its memory).
528
- * Returns 1 on success, 0 on failure.
529
- */
530
- CMARK_GFM_EXPORT int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode);
531
-
532
- /** Adds 'child' to the beginning of the children of 'node'.
533
- * Returns 1 on success, 0 on failure.
534
- */
535
- CMARK_GFM_EXPORT int cmark_node_prepend_child(cmark_node *node, cmark_node *child);
536
-
537
- /** Adds 'child' to the end of the children of 'node'.
538
- * Returns 1 on success, 0 on failure.
539
- */
540
- CMARK_GFM_EXPORT int cmark_node_append_child(cmark_node *node, cmark_node *child);
541
-
542
- /** Consolidates adjacent text nodes.
543
- */
544
- CMARK_GFM_EXPORT void cmark_consolidate_text_nodes(cmark_node *root);
545
-
546
- /** Ensures a node and all its children own their own chunk memory.
547
- */
548
- CMARK_GFM_EXPORT void cmark_node_own(cmark_node *root);
549
-
550
- /**
551
- * ## Parsing
552
- *
553
- * Simple interface:
554
- *
555
- * cmark_node *document = cmark_parse_document("Hello *world*", 13,
556
- * CMARK_OPT_DEFAULT);
557
- *
558
- * Streaming interface:
559
- *
560
- * cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT);
561
- * FILE *fp = fopen("myfile.md", "rb");
562
- * while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
563
- * cmark_parser_feed(parser, buffer, bytes);
564
- * if (bytes < sizeof(buffer)) {
565
- * break;
566
- * }
567
- * }
568
- * document = cmark_parser_finish(parser);
569
- * cmark_parser_free(parser);
570
- */
571
-
572
- /** Creates a new parser object.
573
- */
574
- CMARK_GFM_EXPORT
575
- cmark_parser *cmark_parser_new(int options);
576
-
577
- /** Creates a new parser object with the given memory allocator
578
- */
579
- CMARK_GFM_EXPORT
580
- cmark_parser *cmark_parser_new_with_mem(int options, cmark_mem *mem);
581
-
582
- /** Frees memory allocated for a parser object.
583
- */
584
- CMARK_GFM_EXPORT
585
- void cmark_parser_free(cmark_parser *parser);
586
-
587
- /** Feeds a string of length 'len' to 'parser'.
588
- */
589
- CMARK_GFM_EXPORT
590
- void cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len);
591
-
592
- /** Finish parsing and return a pointer to a tree of nodes.
593
- */
594
- CMARK_GFM_EXPORT
595
- cmark_node *cmark_parser_finish(cmark_parser *parser);
596
-
597
- /** Parse a CommonMark document in 'buffer' of length 'len'.
598
- * Returns a pointer to a tree of nodes. The memory allocated for
599
- * the node tree should be released using 'cmark_node_free'
600
- * when it is no longer needed.
601
- */
602
- CMARK_GFM_EXPORT
603
- cmark_node *cmark_parse_document(const char *buffer, size_t len, int options);
604
-
605
- /** Parse a CommonMark document in file 'f', returning a pointer to
606
- * a tree of nodes. The memory allocated for the node tree should be
607
- * released using 'cmark_node_free' when it is no longer needed.
608
- */
609
- CMARK_GFM_EXPORT
610
- cmark_node *cmark_parse_file(FILE *f, int options);
611
-
612
- /**
613
- * ## Rendering
614
- */
615
-
616
- /** Render a 'node' tree as XML. It is the caller's responsibility
617
- * to free the returned buffer.
618
- */
619
- CMARK_GFM_EXPORT
620
- char *cmark_render_xml(cmark_node *root, int options);
621
-
622
- /** As for 'cmark_render_xml', but specifying the allocator to use for
623
- * the resulting string.
624
- */
625
- CMARK_GFM_EXPORT
626
- char *cmark_render_xml_with_mem(cmark_node *root, int options, cmark_mem *mem);
627
-
628
- /** Render a 'node' tree as an HTML fragment. It is up to the user
629
- * to add an appropriate header and footer. It is the caller's
630
- * responsibility to free the returned buffer.
631
- */
632
- CMARK_GFM_EXPORT
633
- char *cmark_render_html(cmark_node *root, int options, cmark_llist *extensions);
634
-
635
- /** As for 'cmark_render_html', but specifying the allocator to use for
636
- * the resulting string.
637
- */
638
- CMARK_GFM_EXPORT
639
- char *cmark_render_html_with_mem(cmark_node *root, int options, cmark_llist *extensions, cmark_mem *mem);
640
-
641
- /** Render a 'node' tree as a groff man page, without the header.
642
- * It is the caller's responsibility to free the returned buffer.
643
- */
644
- CMARK_GFM_EXPORT
645
- char *cmark_render_man(cmark_node *root, int options, int width);
646
-
647
- /** As for 'cmark_render_man', but specifying the allocator to use for
648
- * the resulting string.
649
- */
650
- CMARK_GFM_EXPORT
651
- char *cmark_render_man_with_mem(cmark_node *root, int options, int width, cmark_mem *mem);
652
-
653
- /** Render a 'node' tree as a commonmark document.
654
- * It is the caller's responsibility to free the returned buffer.
655
- */
656
- CMARK_GFM_EXPORT
657
- char *cmark_render_commonmark(cmark_node *root, int options, int width);
658
-
659
- /** As for 'cmark_render_commonmark', but specifying the allocator to use for
660
- * the resulting string.
661
- */
662
- CMARK_GFM_EXPORT
663
- char *cmark_render_commonmark_with_mem(cmark_node *root, int options, int width, cmark_mem *mem);
664
-
665
- /** Render a 'node' tree as a plain text document.
666
- * It is the caller's responsibility to free the returned buffer.
667
- */
668
- CMARK_GFM_EXPORT
669
- char *cmark_render_plaintext(cmark_node *root, int options, int width);
670
-
671
- /** As for 'cmark_render_plaintext', but specifying the allocator to use for
672
- * the resulting string.
673
- */
674
- CMARK_GFM_EXPORT
675
- char *cmark_render_plaintext_with_mem(cmark_node *root, int options, int width, cmark_mem *mem);
676
-
677
- /** Render a 'node' tree as a LaTeX document.
678
- * It is the caller's responsibility to free the returned buffer.
679
- */
680
- CMARK_GFM_EXPORT
681
- char *cmark_render_latex(cmark_node *root, int options, int width);
682
-
683
- /** As for 'cmark_render_latex', but specifying the allocator to use for
684
- * the resulting string.
685
- */
686
- CMARK_GFM_EXPORT
687
- char *cmark_render_latex_with_mem(cmark_node *root, int options, int width, cmark_mem *mem);
688
-
689
- /**
690
- * ## Options
691
- */
692
-
693
- /** Default options.
694
- */
695
- #define CMARK_OPT_DEFAULT 0
696
-
697
- /**
698
- * ### Options affecting rendering
699
- */
700
-
701
- /** Include a `data-sourcepos` attribute on all block elements.
702
- */
703
- #define CMARK_OPT_SOURCEPOS (1 << 1)
704
-
705
- /** Render `softbreak` elements as hard line breaks.
706
- */
707
- #define CMARK_OPT_HARDBREAKS (1 << 2)
708
-
709
- /** `CMARK_OPT_SAFE` is defined here for API compatibility,
710
- but it no longer has any effect. "Safe" mode is now the default:
711
- set `CMARK_OPT_UNSAFE` to disable it.
712
- */
713
- #define CMARK_OPT_SAFE (1 << 3)
714
-
715
- /** Render raw HTML and unsafe links (`javascript:`, `vbscript:`,
716
- * `file:`, and `data:`, except for `image/png`, `image/gif`,
717
- * `image/jpeg`, or `image/webp` mime types). By default,
718
- * raw HTML is replaced by a placeholder HTML comment. Unsafe
719
- * links are replaced by empty strings.
720
- */
721
- #define CMARK_OPT_UNSAFE (1 << 17)
722
-
723
- /** Render `softbreak` elements as spaces.
724
- */
725
- #define CMARK_OPT_NOBREAKS (1 << 4)
726
-
727
- /**
728
- * ### Options affecting parsing
729
- */
730
-
731
- /** Legacy option (no effect).
732
- */
733
- #define CMARK_OPT_NORMALIZE (1 << 8)
734
-
735
- /** Validate UTF-8 in the input before parsing, replacing illegal
736
- * sequences with the replacement character U+FFFD.
737
- */
738
- #define CMARK_OPT_VALIDATE_UTF8 (1 << 9)
739
-
740
- /** Convert straight quotes to curly, --- to em dashes, -- to en dashes.
741
- */
742
- #define CMARK_OPT_SMART (1 << 10)
743
-
744
- /** Use GitHub-style <pre lang="x"> tags for code blocks instead of <pre><code
745
- * class="language-x">.
746
- */
747
- #define CMARK_OPT_GITHUB_PRE_LANG (1 << 11)
748
-
749
- /** Be liberal in interpreting inline HTML tags.
750
- */
751
- #define CMARK_OPT_LIBERAL_HTML_TAG (1 << 12)
752
-
753
- /** Parse footnotes.
754
- */
755
- #define CMARK_OPT_FOOTNOTES (1 << 13)
756
-
757
- /** Only parse strikethroughs if surrounded by exactly 2 tildes.
758
- * Gives some compatibility with redcarpet.
759
- */
760
- #define CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE (1 << 14)
761
-
762
- /** Use style attributes to align table cells instead of align attributes.
763
- */
764
- #define CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTES (1 << 15)
765
-
766
- /** Include the remainder of the info string in code blocks in
767
- * a separate attribute.
768
- */
769
- #define CMARK_OPT_FULL_INFO_STRING (1 << 16)
770
-
771
- /**
772
- * ## Version information
773
- */
774
-
775
- /** The library version as integer for runtime checks. Also available as
776
- * macro CMARK_VERSION for compile time checks.
777
- *
778
- * * Bits 16-23 contain the major version.
779
- * * Bits 8-15 contain the minor version.
780
- * * Bits 0-7 contain the patchlevel.
781
- *
782
- * In hexadecimal format, the number 0x010203 represents version 1.2.3.
783
- */
784
- CMARK_GFM_EXPORT
785
- int cmark_version(void);
786
-
787
- /** The library version string for runtime checks. Also available as
788
- * macro CMARK_VERSION_STRING for compile time checks.
789
- */
790
- CMARK_GFM_EXPORT
791
- const char *cmark_version_string(void);
792
-
793
- /** # AUTHORS
794
- *
795
- * John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.
796
- */
797
-
798
- #ifndef CMARK_NO_SHORT_NAMES
799
- #define NODE_DOCUMENT CMARK_NODE_DOCUMENT
800
- #define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE
801
- #define NODE_LIST CMARK_NODE_LIST
802
- #define NODE_ITEM CMARK_NODE_ITEM
803
- #define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK
804
- #define NODE_HTML_BLOCK CMARK_NODE_HTML_BLOCK
805
- #define NODE_CUSTOM_BLOCK CMARK_NODE_CUSTOM_BLOCK
806
- #define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH
807
- #define NODE_HEADING CMARK_NODE_HEADING
808
- #define NODE_HEADER CMARK_NODE_HEADER
809
- #define NODE_THEMATIC_BREAK CMARK_NODE_THEMATIC_BREAK
810
- #define NODE_HRULE CMARK_NODE_HRULE
811
- #define NODE_TEXT CMARK_NODE_TEXT
812
- #define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK
813
- #define NODE_LINEBREAK CMARK_NODE_LINEBREAK
814
- #define NODE_CODE CMARK_NODE_CODE
815
- #define NODE_HTML_INLINE CMARK_NODE_HTML_INLINE
816
- #define NODE_CUSTOM_INLINE CMARK_NODE_CUSTOM_INLINE
817
- #define NODE_EMPH CMARK_NODE_EMPH
818
- #define NODE_STRONG CMARK_NODE_STRONG
819
- #define NODE_LINK CMARK_NODE_LINK
820
- #define NODE_IMAGE CMARK_NODE_IMAGE
821
- #define BULLET_LIST CMARK_BULLET_LIST
822
- #define ORDERED_LIST CMARK_ORDERED_LIST
823
- #define PERIOD_DELIM CMARK_PERIOD_DELIM
824
- #define PAREN_DELIM CMARK_PAREN_DELIM
825
- #endif
826
-
827
- typedef int32_t bufsize_t;
828
-
829
- #ifdef __cplusplus
830
- }
831
- #endif
832
-
833
- #endif