commonmarker 0.23.7.pre1 → 1.0.0.pre.2

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 +136 -0
  8. data/ext/commonmarker/src/lib.rs +29 -0
  9. data/lib/commonmarker/config.rb +57 -38
  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 +14 -29
  14. metadata +34 -178
  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,817 +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();
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();
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
- /**
229
- * ## Iterator
230
- *
231
- * An iterator will walk through a tree of nodes, starting from a root
232
- * node, returning one node at a time, together with information about
233
- * whether the node is being entered or exited. The iterator will
234
- * first descend to a child node, if there is one. When there is no
235
- * child, the iterator will go to the next sibling. When there is no
236
- * next sibling, the iterator will return to the parent (but with
237
- * a 'cmark_event_type' of `CMARK_EVENT_EXIT`). The iterator will
238
- * return `CMARK_EVENT_DONE` when it reaches the root node again.
239
- * One natural application is an HTML renderer, where an `ENTER` event
240
- * outputs an open tag and an `EXIT` event outputs a close tag.
241
- * An iterator might also be used to transform an AST in some systematic
242
- * way, for example, turning all level-3 headings into regular paragraphs.
243
- *
244
- * void
245
- * usage_example(cmark_node *root) {
246
- * cmark_event_type ev_type;
247
- * cmark_iter *iter = cmark_iter_new(root);
248
- *
249
- * while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
250
- * cmark_node *cur = cmark_iter_get_node(iter);
251
- * // Do something with `cur` and `ev_type`
252
- * }
253
- *
254
- * cmark_iter_free(iter);
255
- * }
256
- *
257
- * Iterators will never return `EXIT` events for leaf nodes, which are nodes
258
- * of type:
259
- *
260
- * * CMARK_NODE_HTML_BLOCK
261
- * * CMARK_NODE_THEMATIC_BREAK
262
- * * CMARK_NODE_CODE_BLOCK
263
- * * CMARK_NODE_TEXT
264
- * * CMARK_NODE_SOFTBREAK
265
- * * CMARK_NODE_LINEBREAK
266
- * * CMARK_NODE_CODE
267
- * * CMARK_NODE_HTML_INLINE
268
- *
269
- * Nodes must only be modified after an `EXIT` event, or an `ENTER` event for
270
- * leaf nodes.
271
- */
272
-
273
- typedef enum {
274
- CMARK_EVENT_NONE,
275
- CMARK_EVENT_DONE,
276
- CMARK_EVENT_ENTER,
277
- CMARK_EVENT_EXIT
278
- } cmark_event_type;
279
-
280
- /** Creates a new iterator starting at 'root'. The current node and event
281
- * type are undefined until 'cmark_iter_next' is called for the first time.
282
- * The memory allocated for the iterator should be released using
283
- * 'cmark_iter_free' when it is no longer needed.
284
- */
285
- CMARK_GFM_EXPORT
286
- cmark_iter *cmark_iter_new(cmark_node *root);
287
-
288
- /** Frees the memory allocated for an iterator.
289
- */
290
- CMARK_GFM_EXPORT
291
- void cmark_iter_free(cmark_iter *iter);
292
-
293
- /** Advances to the next node and returns the event type (`CMARK_EVENT_ENTER`,
294
- * `CMARK_EVENT_EXIT` or `CMARK_EVENT_DONE`).
295
- */
296
- CMARK_GFM_EXPORT
297
- cmark_event_type cmark_iter_next(cmark_iter *iter);
298
-
299
- /** Returns the current node.
300
- */
301
- CMARK_GFM_EXPORT
302
- cmark_node *cmark_iter_get_node(cmark_iter *iter);
303
-
304
- /** Returns the current event type.
305
- */
306
- CMARK_GFM_EXPORT
307
- cmark_event_type cmark_iter_get_event_type(cmark_iter *iter);
308
-
309
- /** Returns the root node.
310
- */
311
- CMARK_GFM_EXPORT
312
- cmark_node *cmark_iter_get_root(cmark_iter *iter);
313
-
314
- /** Resets the iterator so that the current node is 'current' and
315
- * the event type is 'event_type'. The new current node must be a
316
- * descendant of the root node or the root node itself.
317
- */
318
- CMARK_GFM_EXPORT
319
- void cmark_iter_reset(cmark_iter *iter, cmark_node *current,
320
- cmark_event_type event_type);
321
-
322
- /**
323
- * ## Accessors
324
- */
325
-
326
- /** Returns the user data of 'node'.
327
- */
328
- CMARK_GFM_EXPORT void *cmark_node_get_user_data(cmark_node *node);
329
-
330
- /** Sets arbitrary user data for 'node'. Returns 1 on success,
331
- * 0 on failure.
332
- */
333
- CMARK_GFM_EXPORT int cmark_node_set_user_data(cmark_node *node, void *user_data);
334
-
335
- /** Set free function for user data */
336
- CMARK_GFM_EXPORT
337
- int cmark_node_set_user_data_free_func(cmark_node *node,
338
- cmark_free_func free_func);
339
-
340
- /** Returns the type of 'node', or `CMARK_NODE_NONE` on error.
341
- */
342
- CMARK_GFM_EXPORT cmark_node_type cmark_node_get_type(cmark_node *node);
343
-
344
- /** Like 'cmark_node_get_type', but returns a string representation
345
- of the type, or `"<unknown>"`.
346
- */
347
- CMARK_GFM_EXPORT
348
- const char *cmark_node_get_type_string(cmark_node *node);
349
-
350
- /** Returns the string contents of 'node', or an empty
351
- string if none is set. Returns NULL if called on a
352
- node that does not have string content.
353
- */
354
- CMARK_GFM_EXPORT const char *cmark_node_get_literal(cmark_node *node);
355
-
356
- /** Sets the string contents of 'node'. Returns 1 on success,
357
- * 0 on failure.
358
- */
359
- CMARK_GFM_EXPORT int cmark_node_set_literal(cmark_node *node, const char *content);
360
-
361
- /** Returns the heading level of 'node', or 0 if 'node' is not a heading.
362
- */
363
- CMARK_GFM_EXPORT int cmark_node_get_heading_level(cmark_node *node);
364
-
365
- /* For backwards compatibility */
366
- #define cmark_node_get_header_level cmark_node_get_heading_level
367
- #define cmark_node_set_header_level cmark_node_set_heading_level
368
-
369
- /** Sets the heading level of 'node', returning 1 on success and 0 on error.
370
- */
371
- CMARK_GFM_EXPORT int cmark_node_set_heading_level(cmark_node *node, int level);
372
-
373
- /** Returns the list type of 'node', or `CMARK_NO_LIST` if 'node'
374
- * is not a list.
375
- */
376
- CMARK_GFM_EXPORT cmark_list_type cmark_node_get_list_type(cmark_node *node);
377
-
378
- /** Sets the list type of 'node', returning 1 on success and 0 on error.
379
- */
380
- CMARK_GFM_EXPORT int cmark_node_set_list_type(cmark_node *node,
381
- cmark_list_type type);
382
-
383
- /** Returns the list delimiter type of 'node', or `CMARK_NO_DELIM` if 'node'
384
- * is not a list.
385
- */
386
- CMARK_GFM_EXPORT cmark_delim_type cmark_node_get_list_delim(cmark_node *node);
387
-
388
- /** Sets the list delimiter type of 'node', returning 1 on success and 0
389
- * on error.
390
- */
391
- CMARK_GFM_EXPORT int cmark_node_set_list_delim(cmark_node *node,
392
- cmark_delim_type delim);
393
-
394
- /** Returns starting number of 'node', if it is an ordered list, otherwise 0.
395
- */
396
- CMARK_GFM_EXPORT int cmark_node_get_list_start(cmark_node *node);
397
-
398
- /** Sets starting number of 'node', if it is an ordered list. Returns 1
399
- * on success, 0 on failure.
400
- */
401
- CMARK_GFM_EXPORT int cmark_node_set_list_start(cmark_node *node, int start);
402
-
403
- /** Returns 1 if 'node' is a tight list, 0 otherwise.
404
- */
405
- CMARK_GFM_EXPORT int cmark_node_get_list_tight(cmark_node *node);
406
-
407
- /** Sets the "tightness" of a list. Returns 1 on success, 0 on failure.
408
- */
409
- CMARK_GFM_EXPORT int cmark_node_set_list_tight(cmark_node *node, int tight);
410
-
411
- /** Returns the info string from a fenced code block.
412
- */
413
- CMARK_GFM_EXPORT const char *cmark_node_get_fence_info(cmark_node *node);
414
-
415
- /** Sets the info string in a fenced code block, returning 1 on
416
- * success and 0 on failure.
417
- */
418
- CMARK_GFM_EXPORT int cmark_node_set_fence_info(cmark_node *node, const char *info);
419
-
420
- /** Sets code blocks fencing details
421
- */
422
- CMARK_GFM_EXPORT int cmark_node_set_fenced(cmark_node * node, int fenced,
423
- int length, int offset, char character);
424
-
425
- /** Returns code blocks fencing details
426
- */
427
- CMARK_GFM_EXPORT int cmark_node_get_fenced(cmark_node *node, int *length, int *offset, char *character);
428
-
429
- /** Returns the URL of a link or image 'node', or an empty string
430
- if no URL is set. Returns NULL if called on a node that is
431
- not a link or image.
432
- */
433
- CMARK_GFM_EXPORT const char *cmark_node_get_url(cmark_node *node);
434
-
435
- /** Sets the URL of a link or image 'node'. Returns 1 on success,
436
- * 0 on failure.
437
- */
438
- CMARK_GFM_EXPORT int cmark_node_set_url(cmark_node *node, const char *url);
439
-
440
- /** Returns the title of a link or image 'node', or an empty
441
- string if no title is set. Returns NULL if called on a node
442
- that is not a link or image.
443
- */
444
- CMARK_GFM_EXPORT const char *cmark_node_get_title(cmark_node *node);
445
-
446
- /** Sets the title of a link or image 'node'. Returns 1 on success,
447
- * 0 on failure.
448
- */
449
- CMARK_GFM_EXPORT int cmark_node_set_title(cmark_node *node, const char *title);
450
-
451
- /** Returns the literal "on enter" text for a custom 'node', or
452
- an empty string if no on_enter is set. Returns NULL if called
453
- on a non-custom node.
454
- */
455
- CMARK_GFM_EXPORT const char *cmark_node_get_on_enter(cmark_node *node);
456
-
457
- /** Sets the literal text to render "on enter" for a custom 'node'.
458
- Any children of the node will be rendered after this text.
459
- Returns 1 on success 0 on failure.
460
- */
461
- CMARK_GFM_EXPORT int cmark_node_set_on_enter(cmark_node *node,
462
- const char *on_enter);
463
-
464
- /** Returns the literal "on exit" text for a custom 'node', or
465
- an empty string if no on_exit is set. Returns NULL if
466
- called on a non-custom node.
467
- */
468
- CMARK_GFM_EXPORT const char *cmark_node_get_on_exit(cmark_node *node);
469
-
470
- /** Sets the literal text to render "on exit" for a custom 'node'.
471
- Any children of the node will be rendered before this text.
472
- Returns 1 on success 0 on failure.
473
- */
474
- CMARK_GFM_EXPORT int cmark_node_set_on_exit(cmark_node *node, const char *on_exit);
475
-
476
- /** Returns the line on which 'node' begins.
477
- */
478
- CMARK_GFM_EXPORT int cmark_node_get_start_line(cmark_node *node);
479
-
480
- /** Returns the column at which 'node' begins.
481
- */
482
- CMARK_GFM_EXPORT int cmark_node_get_start_column(cmark_node *node);
483
-
484
- /** Returns the line on which 'node' ends.
485
- */
486
- CMARK_GFM_EXPORT int cmark_node_get_end_line(cmark_node *node);
487
-
488
- /** Returns the column at which 'node' ends.
489
- */
490
- CMARK_GFM_EXPORT int cmark_node_get_end_column(cmark_node *node);
491
-
492
- /**
493
- * ## Tree Manipulation
494
- */
495
-
496
- /** Unlinks a 'node', removing it from the tree, but not freeing its
497
- * memory. (Use 'cmark_node_free' for that.)
498
- */
499
- CMARK_GFM_EXPORT void cmark_node_unlink(cmark_node *node);
500
-
501
- /** Inserts 'sibling' before 'node'. Returns 1 on success, 0 on failure.
502
- */
503
- CMARK_GFM_EXPORT int cmark_node_insert_before(cmark_node *node,
504
- cmark_node *sibling);
505
-
506
- /** Inserts 'sibling' after 'node'. Returns 1 on success, 0 on failure.
507
- */
508
- CMARK_GFM_EXPORT int cmark_node_insert_after(cmark_node *node, cmark_node *sibling);
509
-
510
- /** Replaces 'oldnode' with 'newnode' and unlinks 'oldnode' (but does
511
- * not free its memory).
512
- * Returns 1 on success, 0 on failure.
513
- */
514
- CMARK_GFM_EXPORT int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode);
515
-
516
- /** Adds 'child' to the beginning of the children of 'node'.
517
- * Returns 1 on success, 0 on failure.
518
- */
519
- CMARK_GFM_EXPORT int cmark_node_prepend_child(cmark_node *node, cmark_node *child);
520
-
521
- /** Adds 'child' to the end of the children of 'node'.
522
- * Returns 1 on success, 0 on failure.
523
- */
524
- CMARK_GFM_EXPORT int cmark_node_append_child(cmark_node *node, cmark_node *child);
525
-
526
- /** Consolidates adjacent text nodes.
527
- */
528
- CMARK_GFM_EXPORT void cmark_consolidate_text_nodes(cmark_node *root);
529
-
530
- /** Ensures a node and all its children own their own chunk memory.
531
- */
532
- CMARK_GFM_EXPORT void cmark_node_own(cmark_node *root);
533
-
534
- /**
535
- * ## Parsing
536
- *
537
- * Simple interface:
538
- *
539
- * cmark_node *document = cmark_parse_document("Hello *world*", 13,
540
- * CMARK_OPT_DEFAULT);
541
- *
542
- * Streaming interface:
543
- *
544
- * cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT);
545
- * FILE *fp = fopen("myfile.md", "rb");
546
- * while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
547
- * cmark_parser_feed(parser, buffer, bytes);
548
- * if (bytes < sizeof(buffer)) {
549
- * break;
550
- * }
551
- * }
552
- * document = cmark_parser_finish(parser);
553
- * cmark_parser_free(parser);
554
- */
555
-
556
- /** Creates a new parser object.
557
- */
558
- CMARK_GFM_EXPORT
559
- cmark_parser *cmark_parser_new(int options);
560
-
561
- /** Creates a new parser object with the given memory allocator
562
- */
563
- CMARK_GFM_EXPORT
564
- cmark_parser *cmark_parser_new_with_mem(int options, cmark_mem *mem);
565
-
566
- /** Frees memory allocated for a parser object.
567
- */
568
- CMARK_GFM_EXPORT
569
- void cmark_parser_free(cmark_parser *parser);
570
-
571
- /** Feeds a string of length 'len' to 'parser'.
572
- */
573
- CMARK_GFM_EXPORT
574
- void cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len);
575
-
576
- /** Finish parsing and return a pointer to a tree of nodes.
577
- */
578
- CMARK_GFM_EXPORT
579
- cmark_node *cmark_parser_finish(cmark_parser *parser);
580
-
581
- /** Parse a CommonMark document in 'buffer' of length 'len'.
582
- * Returns a pointer to a tree of nodes. The memory allocated for
583
- * the node tree should be released using 'cmark_node_free'
584
- * when it is no longer needed.
585
- */
586
- CMARK_GFM_EXPORT
587
- cmark_node *cmark_parse_document(const char *buffer, size_t len, int options);
588
-
589
- /** Parse a CommonMark document in file 'f', returning a pointer to
590
- * a tree of nodes. The memory allocated for the node tree should be
591
- * released using 'cmark_node_free' when it is no longer needed.
592
- */
593
- CMARK_GFM_EXPORT
594
- cmark_node *cmark_parse_file(FILE *f, int options);
595
-
596
- /**
597
- * ## Rendering
598
- */
599
-
600
- /** Render a 'node' tree as XML. It is the caller's responsibility
601
- * to free the returned buffer.
602
- */
603
- CMARK_GFM_EXPORT
604
- char *cmark_render_xml(cmark_node *root, int options);
605
-
606
- /** As for 'cmark_render_xml', but specifying the allocator to use for
607
- * the resulting string.
608
- */
609
- CMARK_GFM_EXPORT
610
- char *cmark_render_xml_with_mem(cmark_node *root, int options, cmark_mem *mem);
611
-
612
- /** Render a 'node' tree as an HTML fragment. It is up to the user
613
- * to add an appropriate header and footer. It is the caller's
614
- * responsibility to free the returned buffer.
615
- */
616
- CMARK_GFM_EXPORT
617
- char *cmark_render_html(cmark_node *root, int options, cmark_llist *extensions);
618
-
619
- /** As for 'cmark_render_html', but specifying the allocator to use for
620
- * the resulting string.
621
- */
622
- CMARK_GFM_EXPORT
623
- char *cmark_render_html_with_mem(cmark_node *root, int options, cmark_llist *extensions, cmark_mem *mem);
624
-
625
- /** Render a 'node' tree as a groff man page, without the header.
626
- * It is the caller's responsibility to free the returned buffer.
627
- */
628
- CMARK_GFM_EXPORT
629
- char *cmark_render_man(cmark_node *root, int options, int width);
630
-
631
- /** As for 'cmark_render_man', but specifying the allocator to use for
632
- * the resulting string.
633
- */
634
- CMARK_GFM_EXPORT
635
- char *cmark_render_man_with_mem(cmark_node *root, int options, int width, cmark_mem *mem);
636
-
637
- /** Render a 'node' tree as a commonmark document.
638
- * It is the caller's responsibility to free the returned buffer.
639
- */
640
- CMARK_GFM_EXPORT
641
- char *cmark_render_commonmark(cmark_node *root, int options, int width);
642
-
643
- /** As for 'cmark_render_commonmark', but specifying the allocator to use for
644
- * the resulting string.
645
- */
646
- CMARK_GFM_EXPORT
647
- char *cmark_render_commonmark_with_mem(cmark_node *root, int options, int width, cmark_mem *mem);
648
-
649
- /** Render a 'node' tree as a plain text document.
650
- * It is the caller's responsibility to free the returned buffer.
651
- */
652
- CMARK_GFM_EXPORT
653
- char *cmark_render_plaintext(cmark_node *root, int options, int width);
654
-
655
- /** As for 'cmark_render_plaintext', but specifying the allocator to use for
656
- * the resulting string.
657
- */
658
- CMARK_GFM_EXPORT
659
- char *cmark_render_plaintext_with_mem(cmark_node *root, int options, int width, cmark_mem *mem);
660
-
661
- /** Render a 'node' tree as a LaTeX document.
662
- * It is the caller's responsibility to free the returned buffer.
663
- */
664
- CMARK_GFM_EXPORT
665
- char *cmark_render_latex(cmark_node *root, int options, int width);
666
-
667
- /** As for 'cmark_render_latex', but specifying the allocator to use for
668
- * the resulting string.
669
- */
670
- CMARK_GFM_EXPORT
671
- char *cmark_render_latex_with_mem(cmark_node *root, int options, int width, cmark_mem *mem);
672
-
673
- /**
674
- * ## Options
675
- */
676
-
677
- /** Default options.
678
- */
679
- #define CMARK_OPT_DEFAULT 0
680
-
681
- /**
682
- * ### Options affecting rendering
683
- */
684
-
685
- /** Include a `data-sourcepos` attribute on all block elements.
686
- */
687
- #define CMARK_OPT_SOURCEPOS (1 << 1)
688
-
689
- /** Render `softbreak` elements as hard line breaks.
690
- */
691
- #define CMARK_OPT_HARDBREAKS (1 << 2)
692
-
693
- /** `CMARK_OPT_SAFE` is defined here for API compatibility,
694
- but it no longer has any effect. "Safe" mode is now the default:
695
- set `CMARK_OPT_UNSAFE` to disable it.
696
- */
697
- #define CMARK_OPT_SAFE (1 << 3)
698
-
699
- /** Render raw HTML and unsafe links (`javascript:`, `vbscript:`,
700
- * `file:`, and `data:`, except for `image/png`, `image/gif`,
701
- * `image/jpeg`, or `image/webp` mime types). By default,
702
- * raw HTML is replaced by a placeholder HTML comment. Unsafe
703
- * links are replaced by empty strings.
704
- */
705
- #define CMARK_OPT_UNSAFE (1 << 17)
706
-
707
- /** Render `softbreak` elements as spaces.
708
- */
709
- #define CMARK_OPT_NOBREAKS (1 << 4)
710
-
711
- /**
712
- * ### Options affecting parsing
713
- */
714
-
715
- /** Legacy option (no effect).
716
- */
717
- #define CMARK_OPT_NORMALIZE (1 << 8)
718
-
719
- /** Validate UTF-8 in the input before parsing, replacing illegal
720
- * sequences with the replacement character U+FFFD.
721
- */
722
- #define CMARK_OPT_VALIDATE_UTF8 (1 << 9)
723
-
724
- /** Convert straight quotes to curly, --- to em dashes, -- to en dashes.
725
- */
726
- #define CMARK_OPT_SMART (1 << 10)
727
-
728
- /** Use GitHub-style <pre lang="x"> tags for code blocks instead of <pre><code
729
- * class="language-x">.
730
- */
731
- #define CMARK_OPT_GITHUB_PRE_LANG (1 << 11)
732
-
733
- /** Be liberal in interpreting inline HTML tags.
734
- */
735
- #define CMARK_OPT_LIBERAL_HTML_TAG (1 << 12)
736
-
737
- /** Parse footnotes.
738
- */
739
- #define CMARK_OPT_FOOTNOTES (1 << 13)
740
-
741
- /** Only parse strikethroughs if surrounded by exactly 2 tildes.
742
- * Gives some compatibility with redcarpet.
743
- */
744
- #define CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE (1 << 14)
745
-
746
- /** Use style attributes to align table cells instead of align attributes.
747
- */
748
- #define CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTES (1 << 15)
749
-
750
- /** Include the remainder of the info string in code blocks in
751
- * a separate attribute.
752
- */
753
- #define CMARK_OPT_FULL_INFO_STRING (1 << 16)
754
-
755
- /**
756
- * ## Version information
757
- */
758
-
759
- /** The library version as integer for runtime checks. Also available as
760
- * macro CMARK_VERSION for compile time checks.
761
- *
762
- * * Bits 16-23 contain the major version.
763
- * * Bits 8-15 contain the minor version.
764
- * * Bits 0-7 contain the patchlevel.
765
- *
766
- * In hexadecimal format, the number 0x010203 represents version 1.2.3.
767
- */
768
- CMARK_GFM_EXPORT
769
- int cmark_version(void);
770
-
771
- /** The library version string for runtime checks. Also available as
772
- * macro CMARK_VERSION_STRING for compile time checks.
773
- */
774
- CMARK_GFM_EXPORT
775
- const char *cmark_version_string(void);
776
-
777
- /** # AUTHORS
778
- *
779
- * John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.
780
- */
781
-
782
- #ifndef CMARK_NO_SHORT_NAMES
783
- #define NODE_DOCUMENT CMARK_NODE_DOCUMENT
784
- #define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE
785
- #define NODE_LIST CMARK_NODE_LIST
786
- #define NODE_ITEM CMARK_NODE_ITEM
787
- #define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK
788
- #define NODE_HTML_BLOCK CMARK_NODE_HTML_BLOCK
789
- #define NODE_CUSTOM_BLOCK CMARK_NODE_CUSTOM_BLOCK
790
- #define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH
791
- #define NODE_HEADING CMARK_NODE_HEADING
792
- #define NODE_HEADER CMARK_NODE_HEADER
793
- #define NODE_THEMATIC_BREAK CMARK_NODE_THEMATIC_BREAK
794
- #define NODE_HRULE CMARK_NODE_HRULE
795
- #define NODE_TEXT CMARK_NODE_TEXT
796
- #define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK
797
- #define NODE_LINEBREAK CMARK_NODE_LINEBREAK
798
- #define NODE_CODE CMARK_NODE_CODE
799
- #define NODE_HTML_INLINE CMARK_NODE_HTML_INLINE
800
- #define NODE_CUSTOM_INLINE CMARK_NODE_CUSTOM_INLINE
801
- #define NODE_EMPH CMARK_NODE_EMPH
802
- #define NODE_STRONG CMARK_NODE_STRONG
803
- #define NODE_LINK CMARK_NODE_LINK
804
- #define NODE_IMAGE CMARK_NODE_IMAGE
805
- #define BULLET_LIST CMARK_BULLET_LIST
806
- #define ORDERED_LIST CMARK_ORDERED_LIST
807
- #define PERIOD_DELIM CMARK_PERIOD_DELIM
808
- #define PAREN_DELIM CMARK_PAREN_DELIM
809
- #endif
810
-
811
- typedef int32_t bufsize_t;
812
-
813
- #ifdef __cplusplus
814
- }
815
- #endif
816
-
817
- #endif