|
1
|
#ifndef CMARK_H |
|
2
|
#define CMARK_H |
|
3
|
|
|
4
|
#include <stdio.h> |
|
5
|
#include <stdarg.h> |
|
6
|
#include <string.h> |
|
7
|
#include <assert.h> |
|
8
|
#include <string.h> |
|
9
|
#include <stdio.h> |
|
10
|
#include <stdlib.h> |
|
11
|
#include <stdint.h> |
|
12
|
#include <limits.h> |
|
13
|
|
|
14
|
#ifdef __cplusplus |
|
15
|
extern "C" { |
|
16
|
#endif |
|
17
|
#ifndef CMARK_CONFIG_H |
|
18
|
#define CMARK_CONFIG_H |
|
19
|
|
|
20
|
#ifdef __cplusplus |
|
21
|
extern "C" { |
|
22
|
#endif |
|
23
|
|
|
24
|
#define HAVE_STDBOOL_H |
|
25
|
|
|
26
|
#ifdef HAVE_STDBOOL_H |
|
27
|
#include <stdbool.h> |
|
28
|
#elif !defined(__cplusplus) |
|
29
|
typedef char bool; |
|
30
|
#endif |
|
31
|
|
|
32
|
#define HAVE___BUILTIN_EXPECT |
|
33
|
|
|
34
|
#define HAVE___ATTRIBUTE__ |
|
35
|
|
|
36
|
#ifdef HAVE___ATTRIBUTE__ |
|
37
|
#define CMARK_ATTRIBUTE(list) __attribute__ (list) |
|
38
|
#else |
|
39
|
#define CMARK_ATTRIBUTE(list) |
|
40
|
#endif |
|
41
|
|
|
42
|
#ifndef CMARK_INLINE |
|
43
|
#if defined(_MSC_VER) && !defined(__cplusplus) |
|
44
|
#define CMARK_INLINE __inline |
|
45
|
#else |
|
46
|
#define CMARK_INLINE inline |
|
47
|
#endif |
|
48
|
#endif |
|
49
|
|
|
50
|
/* snprintf and vsnprintf fallbacks for MSVC before 2015, |
|
51
|
due to Valentin Milea http://stackoverflow.com/questions/2915672/ |
|
52
|
*/ |
|
53
|
|
|
54
|
#if defined(_MSC_VER) && _MSC_VER < 1900 |
|
55
|
|
|
56
|
#include <stdio.h> |
|
57
|
#include <stdarg.h> |
|
58
|
|
|
59
|
#define snprintf c99_snprintf |
|
60
|
#define vsnprintf c99_vsnprintf |
|
61
|
|
|
62
|
CMARK_INLINE int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) |
|
63
|
{ |
|
64
|
int count = -1; |
|
65
|
|
|
66
|
if (size != 0) |
|
67
|
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap); |
|
68
|
if (count == -1) |
|
69
|
count = _vscprintf(format, ap); |
|
70
|
|
|
71
|
return count; |
|
72
|
} |
|
73
|
|
|
74
|
CMARK_INLINE int c99_snprintf(char *outBuf, size_t size, const char *format, ...) |
|
75
|
{ |
|
76
|
int count; |
|
77
|
va_list ap; |
|
78
|
|
|
79
|
va_start(ap, format); |
|
80
|
count = c99_vsnprintf(outBuf, size, format, ap); |
|
81
|
va_end(ap); |
|
82
|
|
|
83
|
return count; |
|
84
|
} |
|
85
|
|
|
86
|
#endif |
|
87
|
|
|
88
|
#ifdef __cplusplus |
|
89
|
} |
|
90
|
#endif |
|
91
|
|
|
92
|
#endif |
|
93
|
/** # NAME |
|
94
|
* |
|
95
|
* **cmark** - CommonMark parsing, manipulating, and rendering |
|
96
|
*/ |
|
97
|
#ifndef CMARK_EXPORT_H |
|
98
|
#define CMARK_EXPORT_H |
|
99
|
|
|
100
|
#ifdef CMARK_STATIC_DEFINE |
|
101
|
# define CMARK_EXPORT |
|
102
|
# define CMARK_NO_EXPORT |
|
103
|
#else |
|
104
|
# ifndef CMARK_EXPORT |
|
105
|
# ifdef libcmark_EXPORTS |
|
106
|
/* We are building this library */ |
|
107
|
# define CMARK_EXPORT __attribute__((visibility("default"))) |
|
108
|
# else |
|
109
|
/* We are using this library */ |
|
110
|
# define CMARK_EXPORT __attribute__((visibility("default"))) |
|
111
|
# endif |
|
112
|
# endif |
|
113
|
|
|
114
|
# ifndef CMARK_NO_EXPORT |
|
115
|
# define CMARK_NO_EXPORT __attribute__((visibility("hidden"))) |
|
116
|
# endif |
|
117
|
#endif |
|
118
|
|
|
119
|
#ifndef CMARK_DEPRECATED |
|
120
|
# define CMARK_DEPRECATED __attribute__ ((__deprecated__)) |
|
121
|
#endif |
|
122
|
|
|
123
|
#ifndef CMARK_DEPRECATED_EXPORT |
|
124
|
# define CMARK_DEPRECATED_EXPORT CMARK_EXPORT CMARK_DEPRECATED |
|
125
|
#endif |
|
126
|
|
|
127
|
#ifndef CMARK_DEPRECATED_NO_EXPORT |
|
128
|
# define CMARK_DEPRECATED_NO_EXPORT CMARK_NO_EXPORT CMARK_DEPRECATED |
|
129
|
#endif |
|
130
|
|
|
131
|
#if 0 /* DEFINE_NO_DEPRECATED */ |
|
132
|
# ifndef CMARK_NO_DEPRECATED |
|
133
|
# define CMARK_NO_DEPRECATED |
|
134
|
# endif |
|
135
|
#endif |
|
136
|
|
|
137
|
#endif |
|
138
|
/** # DESCRIPTION |
|
139
|
* |
|
140
|
* ## Simple Interface |
|
141
|
*/ |
|
142
|
|
|
143
|
/** Convert 'text' (assumed to be a UTF-8 encoded string with length |
|
144
|
* 'len') from CommonMark Markdown to HTML, returning a null-terminated, |
|
145
|
* UTF-8-encoded string. It is the caller's responsibility |
|
146
|
* to free the returned buffer. |
|
147
|
*/ |
|
148
|
CMARK_EXPORT |
|
149
|
char *cmark_markdown_to_html(const char *text, size_t len, int options); |
|
150
|
|
|
151
|
/** ## Node Structure |
|
152
|
*/ |
|
153
|
|
|
154
|
typedef enum { |
|
155
|
/* Error status */ |
|
156
|
CMARK_NODE_NONE, |
|
157
|
|
|
158
|
/* Block */ |
|
159
|
CMARK_NODE_DOCUMENT, |
|
160
|
CMARK_NODE_BLOCK_QUOTE, |
|
161
|
CMARK_NODE_LIST, |
|
162
|
CMARK_NODE_ITEM, |
|
163
|
CMARK_NODE_CODE_BLOCK, |
|
164
|
CMARK_NODE_HTML_BLOCK, |
|
165
|
CMARK_NODE_CUSTOM_BLOCK, |
|
166
|
CMARK_NODE_PARAGRAPH, |
|
167
|
CMARK_NODE_HEADING, |
|
168
|
CMARK_NODE_THEMATIC_BREAK, |
|
169
|
|
|
170
|
CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT, |
|
171
|
CMARK_NODE_LAST_BLOCK = CMARK_NODE_THEMATIC_BREAK, |
|
172
|
|
|
173
|
/* Inline */ |
|
174
|
CMARK_NODE_TEXT, |
|
175
|
CMARK_NODE_SOFTBREAK, |
|
176
|
CMARK_NODE_LINEBREAK, |
|
177
|
CMARK_NODE_CODE, |
|
178
|
CMARK_NODE_HTML_INLINE, |
|
179
|
CMARK_NODE_CUSTOM_INLINE, |
|
180
|
CMARK_NODE_EMPH, |
|
181
|
CMARK_NODE_STRONG, |
|
182
|
CMARK_NODE_LINK, |
|
183
|
CMARK_NODE_IMAGE, |
|
184
|
|
|
185
|
CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT, |
|
186
|
CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE, |
|
187
|
} cmark_node_type; |
|
188
|
|
|
189
|
/* For backwards compatibility: */ |
|
190
|
#define CMARK_NODE_HEADER CMARK_NODE_HEADING |
|
191
|
#define CMARK_NODE_HRULE CMARK_NODE_THEMATIC_BREAK |
|
192
|
#define CMARK_NODE_HTML CMARK_NODE_HTML_BLOCK |
|
193
|
#define CMARK_NODE_INLINE_HTML CMARK_NODE_HTML_INLINE |
|
194
|
|
|
195
|
typedef enum { |
|
196
|
CMARK_NO_LIST, |
|
197
|
CMARK_BULLET_LIST, |
|
198
|
CMARK_ORDERED_LIST |
|
199
|
} cmark_list_type; |
|
200
|
|
|
201
|
typedef enum { |
|
202
|
CMARK_NO_DELIM, |
|
203
|
CMARK_PERIOD_DELIM, |
|
204
|
CMARK_PAREN_DELIM |
|
205
|
} cmark_delim_type; |
|
206
|
|
|
207
|
typedef struct cmark_node cmark_node; |
|
208
|
typedef struct cmark_parser cmark_parser; |
|
209
|
typedef struct cmark_iter cmark_iter; |
|
210
|
|
|
211
|
/** |
|
212
|
* ## Custom memory allocator support |
|
213
|
*/ |
|
214
|
|
|
215
|
/** Defines the memory allocation functions to be used by CMark |
|
216
|
* when parsing and allocating a document tree |
|
217
|
*/ |
|
218
|
typedef struct cmark_mem { |
|
219
|
void *(*calloc)(size_t, size_t); |
|
220
|
void *(*realloc)(void *, size_t); |
|
221
|
void (*free)(void *); |
|
222
|
} cmark_mem; |
|
223
|
|
|
224
|
/** |
|
225
|
* ## Creating and Destroying Nodes |
|
226
|
*/ |
|
227
|
|
|
228
|
/** Creates a new node of type 'type'. Note that the node may have |
|
229
|
* other required properties, which it is the caller's responsibility |
|
230
|
* to assign. |
|
231
|
*/ |
|
232
|
CMARK_EXPORT cmark_node *cmark_node_new(cmark_node_type type); |
|
233
|
|
|
234
|
/** Same as `cmark_node_new`, but explicitly listing the memory |
|
235
|
* allocator used to allocate the node. Note: be sure to use the same |
|
236
|
* allocator for every node in a tree, or bad things can happen. |
|
237
|
*/ |
|
238
|
CMARK_EXPORT cmark_node *cmark_node_new_with_mem(cmark_node_type type, |
|
239
|
cmark_mem *mem); |
|
240
|
|
|
241
|
/** Frees the memory allocated for a node and any children. |
|
242
|
*/ |
|
243
|
CMARK_EXPORT void cmark_node_free(cmark_node *node); |
|
244
|
|
|
245
|
/** |
|
246
|
* ## Tree Traversal |
|
247
|
*/ |
|
248
|
|
|
249
|
/** Returns the next node in the sequence after 'node', or NULL if |
|
250
|
* there is none. |
|
251
|
*/ |
|
252
|
CMARK_EXPORT cmark_node *cmark_node_next(cmark_node *node); |
|
253
|
|
|
254
|
/** Returns the previous node in the sequence after 'node', or NULL if |
|
255
|
* there is none. |
|
256
|
*/ |
|
257
|
CMARK_EXPORT cmark_node *cmark_node_previous(cmark_node *node); |
|
258
|
|
|
259
|
/** Returns the parent of 'node', or NULL if there is none. |
|
260
|
*/ |
|
261
|
CMARK_EXPORT cmark_node *cmark_node_parent(cmark_node *node); |
|
262
|
|
|
263
|
/** Returns the first child of 'node', or NULL if 'node' has no children. |
|
264
|
*/ |
|
265
|
CMARK_EXPORT cmark_node *cmark_node_first_child(cmark_node *node); |
|
266
|
|
|
267
|
/** Returns the last child of 'node', or NULL if 'node' has no children. |
|
268
|
*/ |
|
269
|
CMARK_EXPORT cmark_node *cmark_node_last_child(cmark_node *node); |
|
270
|
|
|
271
|
/** |
|
272
|
* ## Iterator |
|
273
|
* |
|
274
|
* An iterator will walk through a tree of nodes, starting from a root |
|
275
|
* node, returning one node at a time, together with information about |
|
276
|
* whether the node is being entered or exited. The iterator will |
|
277
|
* first descend to a child node, if there is one. When there is no |
|
278
|
* child, the iterator will go to the next sibling. When there is no |
|
279
|
* next sibling, the iterator will return to the parent (but with |
|
280
|
* a 'cmark_event_type' of `CMARK_EVENT_EXIT`). The iterator will |
|
281
|
* return `CMARK_EVENT_DONE` when it reaches the root node again. |
|
282
|
* One natural application is an HTML renderer, where an `ENTER` event |
|
283
|
* outputs an open tag and an `EXIT` event outputs a close tag. |
|
284
|
* An iterator might also be used to transform an AST in some systematic |
|
285
|
* way, for example, turning all level-3 headings into regular paragraphs. |
|
286
|
* |
|
287
|
* void |
|
288
|
* usage_example(cmark_node *root) { |
|
289
|
* cmark_event_type ev_type; |
|
290
|
* cmark_iter *iter = cmark_iter_new(root); |
|
291
|
* |
|
292
|
* while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { |
|
293
|
* cmark_node *cur = cmark_iter_get_node(iter); |
|
294
|
* // Do something with `cur` and `ev_type` |
|
295
|
* } |
|
296
|
* |
|
297
|
* cmark_iter_free(iter); |
|
298
|
* } |
|
299
|
* |
|
300
|
* Iterators will never return `EXIT` events for leaf nodes, which are nodes |
|
301
|
* of type: |
|
302
|
* |
|
303
|
* * CMARK_NODE_HTML_BLOCK |
|
304
|
* * CMARK_NODE_THEMATIC_BREAK |
|
305
|
* * CMARK_NODE_CODE_BLOCK |
|
306
|
* * CMARK_NODE_TEXT |
|
307
|
* * CMARK_NODE_SOFTBREAK |
|
308
|
* * CMARK_NODE_LINEBREAK |
|
309
|
* * CMARK_NODE_CODE |
|
310
|
* * CMARK_NODE_HTML_INLINE |
|
311
|
* |
|
312
|
* Nodes must only be modified after an `EXIT` event, or an `ENTER` event for |
|
313
|
* leaf nodes. |
|
314
|
*/ |
|
315
|
|
|
316
|
typedef enum { |
|
317
|
CMARK_EVENT_NONE, |
|
318
|
CMARK_EVENT_DONE, |
|
319
|
CMARK_EVENT_ENTER, |
|
320
|
CMARK_EVENT_EXIT |
|
321
|
} cmark_event_type; |
|
322
|
|
|
323
|
/** Creates a new iterator starting at 'root'. The current node and event |
|
324
|
* type are undefined until 'cmark_iter_next' is called for the first time. |
|
325
|
* The memory allocated for the iterator should be released using |
|
326
|
* 'cmark_iter_free' when it is no longer needed. |
|
327
|
*/ |
|
328
|
CMARK_EXPORT |
|
329
|
cmark_iter *cmark_iter_new(cmark_node *root); |
|
330
|
|
|
331
|
/** Frees the memory allocated for an iterator. |
|
332
|
*/ |
|
333
|
CMARK_EXPORT |
|
334
|
void cmark_iter_free(cmark_iter *iter); |
|
335
|
|
|
336
|
/** Advances to the next node and returns the event type (`CMARK_EVENT_ENTER`, |
|
337
|
* `CMARK_EVENT_EXIT` or `CMARK_EVENT_DONE`). |
|
338
|
*/ |
|
339
|
CMARK_EXPORT |
|
340
|
cmark_event_type cmark_iter_next(cmark_iter *iter); |
|
341
|
|
|
342
|
/** Returns the current node. |
|
343
|
*/ |
|
344
|
CMARK_EXPORT |
|
345
|
cmark_node *cmark_iter_get_node(cmark_iter *iter); |
|
346
|
|
|
347
|
/** Returns the current event type. |
|
348
|
*/ |
|
349
|
CMARK_EXPORT |
|
350
|
cmark_event_type cmark_iter_get_event_type(cmark_iter *iter); |
|
351
|
|
|
352
|
/** Returns the root node. |
|
353
|
*/ |
|
354
|
CMARK_EXPORT |
|
355
|
cmark_node *cmark_iter_get_root(cmark_iter *iter); |
|
356
|
|
|
357
|
/** Resets the iterator so that the current node is 'current' and |
|
358
|
* the event type is 'event_type'. The new current node must be a |
|
359
|
* descendant of the root node or the root node itself. |
|
360
|
*/ |
|
361
|
CMARK_EXPORT |
|
362
|
void cmark_iter_reset(cmark_iter *iter, cmark_node *current, |
|
363
|
cmark_event_type event_type); |
|
364
|
|
|
365
|
/** |
|
366
|
* ## Accessors |
|
367
|
*/ |
|
368
|
|
|
369
|
/** Returns the user data of 'node'. |
|
370
|
*/ |
|
371
|
CMARK_EXPORT void *cmark_node_get_user_data(cmark_node *node); |
|
372
|
|
|
373
|
/** Sets arbitrary user data for 'node'. Returns 1 on success, |
|
374
|
* 0 on failure. |
|
375
|
*/ |
|
376
|
CMARK_EXPORT int cmark_node_set_user_data(cmark_node *node, void *user_data); |
|
377
|
|
|
378
|
/** Returns the type of 'node', or `CMARK_NODE_NONE` on error. |
|
379
|
*/ |
|
380
|
CMARK_EXPORT cmark_node_type cmark_node_get_type(cmark_node *node); |
|
381
|
|
|
382
|
/** Like 'cmark_node_get_type', but returns a string representation |
|
383
|
of the type, or `"<unknown>"`. |
|
384
|
*/ |
|
385
|
CMARK_EXPORT |
|
386
|
const char *cmark_node_get_type_string(cmark_node *node); |
|
387
|
|
|
388
|
/** Returns the string contents of 'node', or an empty |
|
389
|
string if none is set. |
|
390
|
*/ |
|
391
|
CMARK_EXPORT const char *cmark_node_get_literal(cmark_node *node); |
|
392
|
|
|
393
|
/** Sets the string contents of 'node'. Returns 1 on success, |
|
394
|
* 0 on failure. |
|
395
|
*/ |
|
396
|
CMARK_EXPORT int cmark_node_set_literal(cmark_node *node, const char *content); |
|
397
|
|
|
398
|
/** Returns the heading level of 'node', or 0 if 'node' is not a heading. |
|
399
|
*/ |
|
400
|
CMARK_EXPORT int cmark_node_get_heading_level(cmark_node *node); |
|
401
|
|
|
402
|
/* For backwards compatibility */ |
|
403
|
#define cmark_node_get_header_level cmark_node_get_heading_level |
|
404
|
#define cmark_node_set_header_level cmark_node_set_heading_level |
|
405
|
|
|
406
|
/** Sets the heading level of 'node', returning 1 on success and 0 on error. |
|
407
|
*/ |
|
408
|
CMARK_EXPORT int cmark_node_set_heading_level(cmark_node *node, int level); |
|
409
|
|
|
410
|
/** Returns the list type of 'node', or `CMARK_NO_LIST` if 'node' |
|
411
|
* is not a list. |
|
412
|
*/ |
|
413
|
CMARK_EXPORT cmark_list_type cmark_node_get_list_type(cmark_node *node); |
|
414
|
|
|
415
|
/** Sets the list type of 'node', returning 1 on success and 0 on error. |
|
416
|
*/ |
|
417
|
CMARK_EXPORT int cmark_node_set_list_type(cmark_node *node, |
|
418
|
cmark_list_type type); |
|
419
|
|
|
420
|
/** Returns the list delimiter type of 'node', or `CMARK_NO_DELIM` if 'node' |
|
421
|
* is not a list. |
|
422
|
*/ |
|
423
|
CMARK_EXPORT cmark_delim_type cmark_node_get_list_delim(cmark_node *node); |
|
424
|
|
|
425
|
/** Sets the list delimiter type of 'node', returning 1 on success and 0 |
|
426
|
* on error. |
|
427
|
*/ |
|
428
|
CMARK_EXPORT int cmark_node_set_list_delim(cmark_node *node, |
|
429
|
cmark_delim_type delim); |
|
430
|
|
|
431
|
/** Returns starting number of 'node', if it is an ordered list, otherwise 0. |
|
432
|
*/ |
|
433
|
CMARK_EXPORT int cmark_node_get_list_start(cmark_node *node); |
|
434
|
|
|
435
|
/** Sets starting number of 'node', if it is an ordered list. Returns 1 |
|
436
|
* on success, 0 on failure. |
|
437
|
*/ |
|
438
|
CMARK_EXPORT int cmark_node_set_list_start(cmark_node *node, int start); |
|
439
|
|
|
440
|
/** Returns 1 if 'node' is a tight list, 0 otherwise. |
|
441
|
*/ |
|
442
|
CMARK_EXPORT int cmark_node_get_list_tight(cmark_node *node); |
|
443
|
|
|
444
|
/** Sets the "tightness" of a list. Returns 1 on success, 0 on failure. |
|
445
|
*/ |
|
446
|
CMARK_EXPORT int cmark_node_set_list_tight(cmark_node *node, int tight); |
|
447
|
|
|
448
|
/** Returns the info string from a fenced code block. |
|
449
|
*/ |
|
450
|
CMARK_EXPORT const char *cmark_node_get_fence_info(cmark_node *node); |
|
451
|
|
|
452
|
/** Sets the info string in a fenced code block, returning 1 on |
|
453
|
* success and 0 on failure. |
|
454
|
*/ |
|
455
|
CMARK_EXPORT int cmark_node_set_fence_info(cmark_node *node, const char *info); |
|
456
|
|
|
457
|
/** Returns the URL of a link or image 'node', or an empty string |
|
458
|
if no URL is set. |
|
459
|
*/ |
|
460
|
CMARK_EXPORT const char *cmark_node_get_url(cmark_node *node); |
|
461
|
|
|
462
|
/** Sets the URL of a link or image 'node'. Returns 1 on success, |
|
463
|
* 0 on failure. |
|
464
|
*/ |
|
465
|
CMARK_EXPORT int cmark_node_set_url(cmark_node *node, const char *url); |
|
466
|
|
|
467
|
/** Returns the title of a link or image 'node', or an empty |
|
468
|
string if no title is set. |
|
469
|
*/ |
|
470
|
CMARK_EXPORT const char *cmark_node_get_title(cmark_node *node); |
|
471
|
|
|
472
|
/** Sets the title of a link or image 'node'. Returns 1 on success, |
|
473
|
* 0 on failure. |
|
474
|
*/ |
|
475
|
CMARK_EXPORT int cmark_node_set_title(cmark_node *node, const char *title); |
|
476
|
|
|
477
|
/** Returns the literal "on enter" text for a custom 'node', or |
|
478
|
an empty string if no on_enter is set. |
|
479
|
*/ |
|
480
|
CMARK_EXPORT const char *cmark_node_get_on_enter(cmark_node *node); |
|
481
|
|
|
482
|
/** Sets the literal text to render "on enter" for a custom 'node'. |
|
483
|
Any children of the node will be rendered after this text. |
|
484
|
Returns 1 on success 0 on failure. |
|
485
|
*/ |
|
486
|
CMARK_EXPORT int cmark_node_set_on_enter(cmark_node *node, |
|
487
|
const char *on_enter); |
|
488
|
|
|
489
|
/** Returns the literal "on exit" text for a custom 'node', or |
|
490
|
an empty string if no on_exit is set. |
|
491
|
*/ |
|
492
|
CMARK_EXPORT const char *cmark_node_get_on_exit(cmark_node *node); |
|
493
|
|
|
494
|
/** Sets the literal text to render "on exit" for a custom 'node'. |
|
495
|
Any children of the node will be rendered before this text. |
|
496
|
Returns 1 on success 0 on failure. |
|
497
|
*/ |
|
498
|
CMARK_EXPORT int cmark_node_set_on_exit(cmark_node *node, const char *on_exit); |
|
499
|
|
|
500
|
/** Returns the line on which 'node' begins. |
|
501
|
*/ |
|
502
|
CMARK_EXPORT int cmark_node_get_start_line(cmark_node *node); |
|
503
|
|
|
504
|
/** Returns the column at which 'node' begins. |
|
505
|
*/ |
|
506
|
CMARK_EXPORT int cmark_node_get_start_column(cmark_node *node); |
|
507
|
|
|
508
|
/** Returns the line on which 'node' ends. |
|
509
|
*/ |
|
510
|
CMARK_EXPORT int cmark_node_get_end_line(cmark_node *node); |
|
511
|
|
|
512
|
/** Returns the column at which 'node' ends. |
|
513
|
*/ |
|
514
|
CMARK_EXPORT int cmark_node_get_end_column(cmark_node *node); |
|
515
|
|
|
516
|
/** |
|
517
|
* ## Tree Manipulation |
|
518
|
*/ |
|
519
|
|
|
520
|
/** Unlinks a 'node', removing it from the tree, but not freeing its |
|
521
|
* memory. (Use 'cmark_node_free' for that.) |
|
522
|
*/ |
|
523
|
CMARK_EXPORT void cmark_node_unlink(cmark_node *node); |
|
524
|
|
|
525
|
/** Inserts 'sibling' before 'node'. Returns 1 on success, 0 on failure. |
|
526
|
*/ |
|
527
|
CMARK_EXPORT int cmark_node_insert_before(cmark_node *node, |
|
528
|
cmark_node *sibling); |
|
529
|
|
|
530
|
/** Inserts 'sibling' after 'node'. Returns 1 on success, 0 on failure. |
|
531
|
*/ |
|
532
|
CMARK_EXPORT int cmark_node_insert_after(cmark_node *node, cmark_node *sibling); |
|
533
|
|
|
534
|
/** Replaces 'oldnode' with 'newnode' and unlinks 'oldnode' (but does |
|
535
|
* not free its memory). |
|
536
|
* Returns 1 on success, 0 on failure. |
|
537
|
*/ |
|
538
|
CMARK_EXPORT int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode); |
|
539
|
|
|
540
|
/** Adds 'child' to the beginning of the children of 'node'. |
|
541
|
* Returns 1 on success, 0 on failure. |
|
542
|
*/ |
|
543
|
CMARK_EXPORT int cmark_node_prepend_child(cmark_node *node, cmark_node *child); |
|
544
|
|
|
545
|
/** Adds 'child' to the end of the children of 'node'. |
|
546
|
* Returns 1 on success, 0 on failure. |
|
547
|
*/ |
|
548
|
CMARK_EXPORT int cmark_node_append_child(cmark_node *node, cmark_node *child); |
|
549
|
|
|
550
|
/** Consolidates adjacent text nodes. |
|
551
|
*/ |
|
552
|
CMARK_EXPORT void cmark_consolidate_text_nodes(cmark_node *root); |
|
553
|
|
|
554
|
/** |
|
555
|
* ## Parsing |
|
556
|
* |
|
557
|
* Simple interface: |
|
558
|
* |
|
559
|
* cmark_node *document = cmark_parse_document("Hello *world*", 13, |
|
560
|
* CMARK_OPT_DEFAULT); |
|
561
|
* |
|
562
|
* Streaming interface: |
|
563
|
* |
|
564
|
* cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT); |
|
565
|
* FILE *fp = fopen("myfile.md", "rb"); |
|
566
|
* while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) { |
|
567
|
* cmark_parser_feed(parser, buffer, bytes); |
|
568
|
* if (bytes < sizeof(buffer)) { |
|
569
|
* break; |
|
570
|
* } |
|
571
|
* } |
|
572
|
* document = cmark_parser_finish(parser); |
|
573
|
* cmark_parser_free(parser); |
|
574
|
*/ |
|
575
|
|
|
576
|
/** Creates a new parser object. |
|
577
|
*/ |
|
578
|
CMARK_EXPORT |
|
579
|
cmark_parser *cmark_parser_new(int options); |
|
580
|
|
|
581
|
/** Creates a new parser object with the given memory allocator |
|
582
|
*/ |
|
583
|
CMARK_EXPORT |
|
584
|
cmark_parser *cmark_parser_new_with_mem(int options, cmark_mem *mem); |
|
585
|
|
|
586
|
/** Frees memory allocated for a parser object. |
|
587
|
*/ |
|
588
|
CMARK_EXPORT |
|
589
|
void cmark_parser_free(cmark_parser *parser); |
|
590
|
|
|
591
|
/** Feeds a string of length 'len' to 'parser'. |
|
592
|
*/ |
|
593
|
CMARK_EXPORT |
|
594
|
void cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len); |
|
595
|
|
|
596
|
/** Finish parsing and return a pointer to a tree of nodes. |
|
597
|
*/ |
|
598
|
CMARK_EXPORT |
|
599
|
cmark_node *cmark_parser_finish(cmark_parser *parser); |
|
600
|
|
|
601
|
/** Parse a CommonMark document in 'buffer' of length 'len'. |
|
602
|
* Returns a pointer to a tree of nodes. The memory allocated for |
|
603
|
* the node tree should be released using 'cmark_node_free' |
|
604
|
* when it is no longer needed. |
|
605
|
*/ |
|
606
|
CMARK_EXPORT |
|
607
|
cmark_node *cmark_parse_document(const char *buffer, size_t len, int options); |
|
608
|
|
|
609
|
/** Parse a CommonMark document in file 'f', returning a pointer to |
|
610
|
* a tree of nodes. The memory allocated for the node tree should be |
|
611
|
* released using 'cmark_node_free' when it is no longer needed. |
|
612
|
*/ |
|
613
|
CMARK_EXPORT |
|
614
|
cmark_node *cmark_parse_file(FILE *f, int options); |
|
615
|
|
|
616
|
/** |
|
617
|
* ## Rendering |
|
618
|
*/ |
|
619
|
|
|
620
|
/** Render a 'node' tree as XML. It is the caller's responsibility |
|
621
|
* to free the returned buffer. |
|
622
|
*/ |
|
623
|
CMARK_EXPORT |
|
624
|
char *cmark_render_xml(cmark_node *root, int options); |
|
625
|
|
|
626
|
/** Render a 'node' tree as an HTML fragment. It is up to the user |
|
627
|
* to add an appropriate header and footer. It is the caller's |
|
628
|
* responsibility to free the returned buffer. |
|
629
|
*/ |
|
630
|
CMARK_EXPORT |
|
631
|
char *cmark_render_html(cmark_node *root, int options); |
|
632
|
|
|
633
|
/** Render a 'node' tree as a groff man page, without the header. |
|
634
|
* It is the caller's responsibility to free the returned buffer. |
|
635
|
*/ |
|
636
|
CMARK_EXPORT |
|
637
|
char *cmark_render_man(cmark_node *root, int options, int width); |
|
638
|
|
|
639
|
/** Render a 'node' tree as a commonmark document. |
|
640
|
* It is the caller's responsibility to free the returned buffer. |
|
641
|
*/ |
|
642
|
CMARK_EXPORT |
|
643
|
char *cmark_render_commonmark(cmark_node *root, int options, int width); |
|
644
|
|
|
645
|
/** Render a 'node' tree as a LaTeX document. |
|
646
|
* It is the caller's responsibility to free the returned buffer. |
|
647
|
*/ |
|
648
|
CMARK_EXPORT |
|
649
|
char *cmark_render_latex(cmark_node *root, int options, int width); |
|
650
|
|
|
651
|
/** |
|
652
|
* ## Options |
|
653
|
*/ |
|
654
|
|
|
655
|
/** Default options. |
|
656
|
*/ |
|
657
|
#define CMARK_OPT_DEFAULT 0 |
|
658
|
|
|
659
|
/** |
|
660
|
* ### Options affecting rendering |
|
661
|
*/ |
|
662
|
|
|
663
|
/** Include a `data-sourcepos` attribute on all block elements. |
|
664
|
*/ |
|
665
|
#define CMARK_OPT_SOURCEPOS (1 << 1) |
|
666
|
|
|
667
|
/** Render `softbreak` elements as hard line breaks. |
|
668
|
*/ |
|
669
|
#define CMARK_OPT_HARDBREAKS (1 << 2) |
|
670
|
|
|
671
|
/** Suppress raw HTML and unsafe links (`javascript:`, `vbscript:`, |
|
672
|
* `file:`, and `data:`, except for `image/png`, `image/gif`, |
|
673
|
* `image/jpeg`, or `image/webp` mime types). Raw HTML is replaced |
|
674
|
* by a placeholder HTML comment. Unsafe links are replaced by |
|
675
|
* empty strings. |
|
676
|
*/ |
|
677
|
#define CMARK_OPT_SAFE (1 << 3) |
|
678
|
|
|
679
|
/** Render `softbreak` elements as spaces. |
|
680
|
*/ |
|
681
|
#define CMARK_OPT_NOBREAKS (1 << 4) |
|
682
|
|
|
683
|
/** |
|
684
|
* ### Options affecting parsing |
|
685
|
*/ |
|
686
|
|
|
687
|
/** Normalize tree by consolidating adjacent text nodes. |
|
688
|
*/ |
|
689
|
#define CMARK_OPT_NORMALIZE (1 << 8) |
|
690
|
|
|
691
|
/** Validate UTF-8 in the input before parsing, replacing illegal |
|
692
|
* sequences with the replacement character U+FFFD. |
|
693
|
*/ |
|
694
|
#define CMARK_OPT_VALIDATE_UTF8 (1 << 9) |
|
695
|
|
|
696
|
/** Convert straight quotes to curly, --- to em dashes, -- to en dashes. |
|
697
|
*/ |
|
698
|
#define CMARK_OPT_SMART (1 << 10) |
|
699
|
|
|
700
|
/** |
|
701
|
* ## Version information |
|
702
|
*/ |
|
703
|
|
|
704
|
/** The library version as integer for runtime checks. Also available as |
|
705
|
* macro CMARK_VERSION for compile time checks. |
|
706
|
* |
|
707
|
* * Bits 16-23 contain the major version. |
|
708
|
* * Bits 8-15 contain the minor version. |
|
709
|
* * Bits 0-7 contain the patchlevel. |
|
710
|
* |
|
711
|
* In hexadecimal format, the number 0x010203 represents version 1.2.3. |
|
712
|
*/ |
|
713
|
CMARK_EXPORT |
|
714
|
int cmark_version(void); |
|
715
|
|
|
716
|
/** The library version string for runtime checks. Also available as |
|
717
|
* macro CMARK_VERSION_STRING for compile time checks. |
|
718
|
*/ |
|
719
|
CMARK_EXPORT |
|
720
|
const char *cmark_version_string(void); |
|
721
|
|
|
722
|
/** # AUTHORS |
|
723
|
* |
|
724
|
* John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer. |
|
725
|
*/ |
|
726
|
|
|
727
|
#ifndef CMARK_NO_SHORT_NAMES |
|
728
|
#define NODE_DOCUMENT CMARK_NODE_DOCUMENT |
|
729
|
#define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE |
|
730
|
#define NODE_LIST CMARK_NODE_LIST |
|
731
|
#define NODE_ITEM CMARK_NODE_ITEM |
|
732
|
#define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK |
|
733
|
#define NODE_HTML_BLOCK CMARK_NODE_HTML_BLOCK |
|
734
|
#define NODE_CUSTOM_BLOCK CMARK_NODE_CUSTOM_BLOCK |
|
735
|
#define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH |
|
736
|
#define NODE_HEADING CMARK_NODE_HEADING |
|
737
|
#define NODE_HEADER CMARK_NODE_HEADER |
|
738
|
#define NODE_THEMATIC_BREAK CMARK_NODE_THEMATIC_BREAK |
|
739
|
#define NODE_HRULE CMARK_NODE_HRULE |
|
740
|
#define NODE_TEXT CMARK_NODE_TEXT |
|
741
|
#define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK |
|
742
|
#define NODE_LINEBREAK CMARK_NODE_LINEBREAK |
|
743
|
#define NODE_CODE CMARK_NODE_CODE |
|
744
|
#define NODE_HTML_INLINE CMARK_NODE_HTML_INLINE |
|
745
|
#define NODE_CUSTOM_INLINE CMARK_NODE_CUSTOM_INLINE |
|
746
|
#define NODE_EMPH CMARK_NODE_EMPH |
|
747
|
#define NODE_STRONG CMARK_NODE_STRONG |
|
748
|
#define NODE_LINK CMARK_NODE_LINK |
|
749
|
#define NODE_IMAGE CMARK_NODE_IMAGE |
|
750
|
#define BULLET_LIST CMARK_BULLET_LIST |
|
751
|
#define ORDERED_LIST CMARK_ORDERED_LIST |
|
752
|
#define PERIOD_DELIM CMARK_PERIOD_DELIM |
|
753
|
#define PAREN_DELIM CMARK_PAREN_DELIM |
|
754
|
#endif |
|
755
|
|
|
756
|
#ifdef __cplusplus |
|
757
|
} |
|
758
|
#endif |
|
759
|
|
|
760
|
#endif |
|
761
|
|
|
762
|
#ifndef CMARK_BUFFER_H |
|
763
|
#define CMARK_BUFFER_H |
|
764
|
|
|
765
|
#include <stddef.h> |
|
766
|
#include <stdarg.h> |
|
767
|
#include <string.h> |
|
768
|
#include <limits.h> |
|
769
|
#include <stdint.h> |
|
770
|
|
|
771
|
#ifdef __cplusplus |
|
772
|
extern "C" { |
|
773
|
#endif |
|
774
|
|
|
775
|
typedef int32_t bufsize_t; |
|
776
|
|
|
777
|
typedef struct { |
|
778
|
cmark_mem *mem; |
|
779
|
unsigned char *ptr; |
|
780
|
bufsize_t asize, size; |
|
781
|
} cmark_strbuf; |
|
782
|
|
|
783
|
extern unsigned char cmark_strbuf__initbuf[]; |
|
784
|
|
|
785
|
#define CMARK_BUF_INIT(mem) \ |
|
786
|
{ mem, cmark_strbuf__initbuf, 0, 0 } |
|
787
|
|
|
788
|
/** |
|
789
|
* Initialize a cmark_strbuf structure. |
|
790
|
* |
|
791
|
* For the cases where CMARK_BUF_INIT cannot be used to do static |
|
792
|
* initialization. |
|
793
|
*/ |
|
794
|
void cmark_strbuf_init(cmark_mem *mem, cmark_strbuf *buf, |
|
795
|
bufsize_t initial_size); |
|
796
|
|
|
797
|
/** |
|
798
|
* Grow the buffer to hold at least `target_size` bytes. |
|
799
|
*/ |
|
800
|
void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size); |
|
801
|
|
|
802
|
void cmark_strbuf_free(cmark_strbuf *buf); |
|
803
|
void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b); |
|
804
|
|
|
805
|
bufsize_t cmark_strbuf_len(const cmark_strbuf *buf); |
|
806
|
|
|
807
|
int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b); |
|
808
|
|
|
809
|
unsigned char *cmark_strbuf_detach(cmark_strbuf *buf); |
|
810
|
void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize, |
|
811
|
const cmark_strbuf *buf); |
|
812
|
|
|
813
|
static CMARK_INLINE const char *cmark_strbuf_cstr(const cmark_strbuf *buf) { |
|
814
|
return (char *)buf->ptr; |
|
815
|
} |
|
816
|
|
|
817
|
#define cmark_strbuf_at(buf, n) ((buf)->ptr[n]) |
|
818
|
|
|
819
|
void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, |
|
820
|
bufsize_t len); |
|
821
|
void cmark_strbuf_sets(cmark_strbuf *buf, const char *string); |
|
822
|
void cmark_strbuf_putc(cmark_strbuf *buf, int c); |
|
823
|
void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, |
|
824
|
bufsize_t len); |
|
825
|
void cmark_strbuf_puts(cmark_strbuf *buf, const char *string); |
|
826
|
void cmark_strbuf_clear(cmark_strbuf *buf); |
|
827
|
|
|
828
|
bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos); |
|
829
|
bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos); |
|
830
|
void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n); |
|
831
|
void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len); |
|
832
|
void cmark_strbuf_rtrim(cmark_strbuf *buf); |
|
833
|
void cmark_strbuf_trim(cmark_strbuf *buf); |
|
834
|
void cmark_strbuf_normalize_whitespace(cmark_strbuf *s); |
|
835
|
void cmark_strbuf_unescape(cmark_strbuf *s); |
|
836
|
|
|
837
|
#ifdef __cplusplus |
|
838
|
} |
|
839
|
#endif |
|
840
|
|
|
841
|
#endif |
|
842
|
|
|
843
|
#ifndef CMARK_CMARK_CTYPE_H |
|
844
|
#define CMARK_CMARK_CTYPE_H |
|
845
|
|
|
846
|
#ifdef __cplusplus |
|
847
|
extern "C" { |
|
848
|
#endif |
|
849
|
|
|
850
|
/** Locale-independent versions of functions from ctype.h. |
|
851
|
* We want cmark to behave the same no matter what the system locale. |
|
852
|
*/ |
|
853
|
|
|
854
|
int cmark_isspace(char c); |
|
855
|
|
|
856
|
int cmark_ispunct(char c); |
|
857
|
|
|
858
|
int cmark_isalnum(char c); |
|
859
|
|
|
860
|
int cmark_isdigit(char c); |
|
861
|
|
|
862
|
int cmark_isalpha(char c); |
|
863
|
|
|
864
|
#ifdef __cplusplus |
|
865
|
} |
|
866
|
#endif |
|
867
|
|
|
868
|
#endif |
|
869
|
|
|
870
|
#ifndef CMARK_CHUNK_H |
|
871
|
#define CMARK_CHUNK_H |
|
872
|
|
|
873
|
#include <string.h> |
|
874
|
#include <stdlib.h> |
|
875
|
#include <assert.h> |
|
876
|
|
|
877
|
#define CMARK_CHUNK_EMPTY \ |
|
878
|
{ NULL, 0, 0 } |
|
879
|
|
|
880
|
typedef struct { |
|
881
|
unsigned char *data; |
|
882
|
bufsize_t len; |
|
883
|
bufsize_t alloc; // also implies a NULL-terminated string |
|
884
|
} cmark_chunk; |
|
885
|
|
|
886
|
static CMARK_INLINE void cmark_chunk_free(cmark_mem *mem, cmark_chunk *c) { |
|
887
|
if (c->alloc) |
|
888
|
mem->free(c->data); |
|
889
|
|
|
890
|
c->data = NULL; |
|
891
|
c->alloc = 0; |
|
892
|
c->len = 0; |
|
893
|
} |
|
894
|
|
|
895
|
static CMARK_INLINE void cmark_chunk_ltrim(cmark_chunk *c) { |
|
896
|
assert(!c->alloc); |
|
897
|
|
|
898
|
while (c->len && cmark_isspace(c->data[0])) { |
|
899
|
c->data++; |
|
900
|
c->len--; |
|
901
|
} |
|
902
|
} |
|
903
|
|
|
904
|
static CMARK_INLINE void cmark_chunk_rtrim(cmark_chunk *c) { |
|
905
|
assert(!c->alloc); |
|
906
|
|
|
907
|
while (c->len > 0) { |
|
908
|
if (!cmark_isspace(c->data[c->len - 1])) |
|
909
|
break; |
|
910
|
|
|
911
|
c->len--; |
|
912
|
} |
|
913
|
} |
|
914
|
|
|
915
|
static CMARK_INLINE void cmark_chunk_trim(cmark_chunk *c) { |
|
916
|
cmark_chunk_ltrim(c); |
|
917
|
cmark_chunk_rtrim(c); |
|
918
|
} |
|
919
|
|
|
920
|
static CMARK_INLINE bufsize_t cmark_chunk_strchr(cmark_chunk *ch, int c, |
|
921
|
bufsize_t offset) { |
|
922
|
const unsigned char *p = |
|
923
|
(unsigned char *)memchr(ch->data + offset, c, ch->len - offset); |
|
924
|
return p ? (bufsize_t)(p - ch->data) : ch->len; |
|
925
|
} |
|
926
|
|
|
927
|
static CMARK_INLINE const char *cmark_chunk_to_cstr(cmark_mem *mem, |
|
928
|
cmark_chunk *c) { |
|
929
|
unsigned char *str; |
|
930
|
|
|
931
|
if (c->alloc) { |
|
932
|
return (char *)c->data; |
|
933
|
} |
|
934
|
str = (unsigned char *)mem->calloc(c->len + 1, 1); |
|
935
|
if (c->len > 0) { |
|
936
|
memcpy(str, c->data, c->len); |
|
937
|
} |
|
938
|
str[c->len] = 0; |
|
939
|
c->data = str; |
|
940
|
c->alloc = 1; |
|
941
|
|
|
942
|
return (char *)str; |
|
943
|
} |
|
944
|
|
|
945
|
static CMARK_INLINE void cmark_chunk_set_cstr(cmark_mem *mem, cmark_chunk *c, |
|
946
|
const char *str) { |
|
947
|
unsigned char *old = c->alloc ? c->data : NULL; |
|
948
|
if (str == NULL) { |
|
949
|
c->len = 0; |
|
950
|
c->data = NULL; |
|
951
|
c->alloc = 0; |
|
952
|
} else { |
|
953
|
c->len = (bufsize_t)strlen(str); |
|
954
|
c->data = (unsigned char *)mem->calloc(c->len + 1, 1); |
|
955
|
c->alloc = 1; |
|
956
|
memcpy(c->data, str, c->len + 1); |
|
957
|
} |
|
958
|
if (old != NULL) { |
|
959
|
mem->free(old); |
|
960
|
} |
|
961
|
} |
|
962
|
|
|
963
|
static CMARK_INLINE cmark_chunk cmark_chunk_literal(const char *data) { |
|
964
|
bufsize_t len = data ? (bufsize_t)strlen(data) : 0; |
|
965
|
cmark_chunk c = {(unsigned char *)data, len, 0}; |
|
966
|
return c; |
|
967
|
} |
|
968
|
|
|
969
|
static CMARK_INLINE cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, |
|
970
|
bufsize_t pos, bufsize_t len) { |
|
971
|
cmark_chunk c = {ch->data + pos, len, 0}; |
|
972
|
return c; |
|
973
|
} |
|
974
|
|
|
975
|
static CMARK_INLINE cmark_chunk cmark_chunk_buf_detach(cmark_strbuf *buf) { |
|
976
|
cmark_chunk c; |
|
977
|
|
|
978
|
c.len = buf->size; |
|
979
|
c.data = cmark_strbuf_detach(buf); |
|
980
|
c.alloc = 1; |
|
981
|
|
|
982
|
return c; |
|
983
|
} |
|
984
|
|
|
985
|
#endif |
|
986
|
|
|
987
|
#ifndef CMARK_NODE_H |
|
988
|
#define CMARK_NODE_H |
|
989
|
|
|
990
|
#ifdef __cplusplus |
|
991
|
extern "C" { |
|
992
|
#endif |
|
993
|
|
|
994
|
#include <stdio.h> |
|
995
|
#include <stdint.h> |
|
996
|
|
|
997
|
|
|
998
|
typedef struct { |
|
999
|
cmark_list_type list_type; |
|
1000
|
int marker_offset; |
|
1001
|
int padding; |
|
1002
|
int start; |
|
1003
|
cmark_delim_type delimiter; |
|
1004
|
unsigned char bullet_char; |
|
1005
|
bool tight; |
|
1006
|
} cmark_list; |
|
1007
|
|
|
1008
|
typedef struct { |
|
1009
|
cmark_chunk info; |
|
1010
|
cmark_chunk literal; |
|
1011
|
uint8_t fence_length; |
|
1012
|
uint8_t fence_offset; |
|
1013
|
unsigned char fence_char; |
|
1014
|
int8_t fenced; |
|
1015
|
} cmark_code; |
|
1016
|
|
|
1017
|
typedef struct { |
|
1018
|
int level; |
|
1019
|
bool setext; |
|
1020
|
} cmark_heading; |
|
1021
|
|
|
1022
|
typedef struct { |
|
1023
|
cmark_chunk url; |
|
1024
|
cmark_chunk title; |
|
1025
|
} cmark_link; |
|
1026
|
|
|
1027
|
typedef struct { |
|
1028
|
cmark_chunk on_enter; |
|
1029
|
cmark_chunk on_exit; |
|
1030
|
} cmark_custom; |
|
1031
|
|
|
1032
|
enum cmark_node__internal_flags { |
|
1033
|
CMARK_NODE__OPEN = (1 << 0), |
|
1034
|
CMARK_NODE__LAST_LINE_BLANK = (1 << 1), |
|
1035
|
}; |
|
1036
|
|
|
1037
|
struct cmark_node { |
|
1038
|
cmark_strbuf content; |
|
1039
|
|
|
1040
|
struct cmark_node *next; |
|
1041
|
struct cmark_node *prev; |
|
1042
|
struct cmark_node *parent; |
|
1043
|
struct cmark_node *first_child; |
|
1044
|
struct cmark_node *last_child; |
|
1045
|
|
|
1046
|
void *user_data; |
|
1047
|
|
|
1048
|
int start_line; |
|
1049
|
int start_column; |
|
1050
|
int end_line; |
|
1051
|
int end_column; |
|
1052
|
uint16_t type; |
|
1053
|
uint16_t flags; |
|
1054
|
|
|
1055
|
union { |
|
1056
|
cmark_chunk literal; |
|
1057
|
cmark_list list; |
|
1058
|
cmark_code code; |
|
1059
|
cmark_heading heading; |
|
1060
|
cmark_link link; |
|
1061
|
cmark_custom custom; |
|
1062
|
int html_block_type; |
|
1063
|
} as; |
|
1064
|
}; |
|
1065
|
|
|
1066
|
static CMARK_INLINE cmark_mem *cmark_node_mem(cmark_node *node) { |
|
1067
|
return node->content.mem; |
|
1068
|
} |
|
1069
|
CMARK_EXPORT int cmark_node_check(cmark_node *node, FILE *out); |
|
1070
|
|
|
1071
|
#ifdef __cplusplus |
|
1072
|
} |
|
1073
|
#endif |
|
1074
|
|
|
1075
|
#endif |
|
1076
|
#ifndef CMARK_HOUDINI_H |
|
1077
|
#define CMARK_HOUDINI_H |
|
1078
|
|
|
1079
|
#ifdef __cplusplus |
|
1080
|
extern "C" { |
|
1081
|
#endif |
|
1082
|
|
|
1083
|
#include <stdint.h> |
|
1084
|
|
|
1085
|
#ifdef HAVE___BUILTIN_EXPECT |
|
1086
|
#define likely(x) __builtin_expect((x), 1) |
|
1087
|
#define unlikely(x) __builtin_expect((x), 0) |
|
1088
|
#else |
|
1089
|
#define likely(x) (x) |
|
1090
|
#define unlikely(x) (x) |
|
1091
|
#endif |
|
1092
|
|
|
1093
|
#ifdef HOUDINI_USE_LOCALE |
|
1094
|
#define _isxdigit(c) isxdigit(c) |
|
1095
|
#define _isdigit(c) isdigit(c) |
|
1096
|
#else |
|
1097
|
/* |
|
1098
|
* Helper _isdigit methods -- do not trust the current locale |
|
1099
|
* */ |
|
1100
|
#define _isxdigit(c) (strchr("0123456789ABCDEFabcdef", (c)) != NULL) |
|
1101
|
#define _isdigit(c) ((c) >= '0' && (c) <= '9') |
|
1102
|
#endif |
|
1103
|
|
|
1104
|
#define HOUDINI_ESCAPED_SIZE(x) (((x)*12) / 10) |
|
1105
|
#define HOUDINI_UNESCAPED_SIZE(x) (x) |
|
1106
|
|
|
1107
|
extern bufsize_t houdini_unescape_ent(cmark_strbuf *ob, const uint8_t *src, |
|
1108
|
bufsize_t size); |
|
1109
|
extern int houdini_escape_html(cmark_strbuf *ob, const uint8_t *src, |
|
1110
|
bufsize_t size); |
|
1111
|
extern int houdini_escape_html0(cmark_strbuf *ob, const uint8_t *src, |
|
1112
|
bufsize_t size, int secure); |
|
1113
|
extern int houdini_unescape_html(cmark_strbuf *ob, const uint8_t *src, |
|
1114
|
bufsize_t size); |
|
1115
|
extern void houdini_unescape_html_f(cmark_strbuf *ob, const uint8_t *src, |
|
1116
|
bufsize_t size); |
|
1117
|
extern int houdini_escape_href(cmark_strbuf *ob, const uint8_t *src, |
|
1118
|
bufsize_t size); |
|
1119
|
|
|
1120
|
#ifdef __cplusplus |
|
1121
|
} |
|
1122
|
#endif |
|
1123
|
|
|
1124
|
#endif |
|
1125
|
#ifndef CMARK_H |
|
1126
|
#define CMARK_H |
|
1127
|
|
|
1128
|
#include <stdio.h> |
|
1129
|
#include <cmark_export.h> |
|
1130
|
#include <cmark_version.h> |
|
1131
|
|
|
1132
|
#ifdef __cplusplus |
|
1133
|
extern "C" { |
|
1134
|
#endif |
|
1135
|
|
|
1136
|
/** # NAME |
|
1137
|
* |
|
1138
|
* **cmark** - CommonMark parsing, manipulating, and rendering |
|
1139
|
*/ |
|
1140
|
|
|
1141
|
/** # DESCRIPTION |
|
1142
|
* |
|
1143
|
* ## Simple Interface |
|
1144
|
*/ |
|
1145
|
|
|
1146
|
/** Convert 'text' (assumed to be a UTF-8 encoded string with length |
|
1147
|
* 'len') from CommonMark Markdown to HTML, returning a null-terminated, |
|
1148
|
* UTF-8-encoded string. It is the caller's responsibility |
|
1149
|
* to free the returned buffer. |
|
1150
|
*/ |
|
1151
|
CMARK_EXPORT |
|
1152
|
char *cmark_markdown_to_html(const char *text, size_t len, int options); |
|
1153
|
|
|
1154
|
/** ## Node Structure |
|
1155
|
*/ |
|
1156
|
|
|
1157
|
typedef enum { |
|
1158
|
/* Error status */ |
|
1159
|
CMARK_NODE_NONE, |
|
1160
|
|
|
1161
|
/* Block */ |
|
1162
|
CMARK_NODE_DOCUMENT, |
|
1163
|
CMARK_NODE_BLOCK_QUOTE, |
|
1164
|
CMARK_NODE_LIST, |
|
1165
|
CMARK_NODE_ITEM, |
|
1166
|
CMARK_NODE_CODE_BLOCK, |
|
1167
|
CMARK_NODE_HTML_BLOCK, |
|
1168
|
CMARK_NODE_CUSTOM_BLOCK, |
|
1169
|
CMARK_NODE_PARAGRAPH, |
|
1170
|
CMARK_NODE_HEADING, |
|
1171
|
CMARK_NODE_THEMATIC_BREAK, |
|
1172
|
|
|
1173
|
CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT, |
|
1174
|
CMARK_NODE_LAST_BLOCK = CMARK_NODE_THEMATIC_BREAK, |
|
1175
|
|
|
1176
|
/* Inline */ |
|
1177
|
CMARK_NODE_TEXT, |
|
1178
|
CMARK_NODE_SOFTBREAK, |
|
1179
|
CMARK_NODE_LINEBREAK, |
|
1180
|
CMARK_NODE_CODE, |
|
1181
|
CMARK_NODE_HTML_INLINE, |
|
1182
|
CMARK_NODE_CUSTOM_INLINE, |
|
1183
|
CMARK_NODE_EMPH, |
|
1184
|
CMARK_NODE_STRONG, |
|
1185
|
CMARK_NODE_LINK, |
|
1186
|
CMARK_NODE_IMAGE, |
|
1187
|
|
|
1188
|
CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT, |
|
1189
|
CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE, |
|
1190
|
} cmark_node_type; |
|
1191
|
|
|
1192
|
/* For backwards compatibility: */ |
|
1193
|
#define CMARK_NODE_HEADER CMARK_NODE_HEADING |
|
1194
|
#define CMARK_NODE_HRULE CMARK_NODE_THEMATIC_BREAK |
|
1195
|
#define CMARK_NODE_HTML CMARK_NODE_HTML_BLOCK |
|
1196
|
#define CMARK_NODE_INLINE_HTML CMARK_NODE_HTML_INLINE |
|
1197
|
|
|
1198
|
typedef enum { |
|
1199
|
CMARK_NO_LIST, |
|
1200
|
CMARK_BULLET_LIST, |
|
1201
|
CMARK_ORDERED_LIST |
|
1202
|
} cmark_list_type; |
|
1203
|
|
|
1204
|
typedef enum { |
|
1205
|
CMARK_NO_DELIM, |
|
1206
|
CMARK_PERIOD_DELIM, |
|
1207
|
CMARK_PAREN_DELIM |
|
1208
|
} cmark_delim_type; |
|
1209
|
|
|
1210
|
typedef struct cmark_node cmark_node; |
|
1211
|
typedef struct cmark_parser cmark_parser; |
|
1212
|
typedef struct cmark_iter cmark_iter; |
|
1213
|
|
|
1214
|
/** |
|
1215
|
* ## Custom memory allocator support |
|
1216
|
*/ |
|
1217
|
|
|
1218
|
/** Defines the memory allocation functions to be used by CMark |
|
1219
|
* when parsing and allocating a document tree |
|
1220
|
*/ |
|
1221
|
typedef struct cmark_mem { |
|
1222
|
void *(*calloc)(size_t, size_t); |
|
1223
|
void *(*realloc)(void *, size_t); |
|
1224
|
void (*free)(void *); |
|
1225
|
} cmark_mem; |
|
1226
|
|
|
1227
|
/** |
|
1228
|
* ## Creating and Destroying Nodes |
|
1229
|
*/ |
|
1230
|
|
|
1231
|
/** Creates a new node of type 'type'. Note that the node may have |
|
1232
|
* other required properties, which it is the caller's responsibility |
|
1233
|
* to assign. |
|
1234
|
*/ |
|
1235
|
CMARK_EXPORT cmark_node *cmark_node_new(cmark_node_type type); |
|
1236
|
|
|
1237
|
/** Same as `cmark_node_new`, but explicitly listing the memory |
|
1238
|
* allocator used to allocate the node. Note: be sure to use the same |
|
1239
|
* allocator for every node in a tree, or bad things can happen. |
|
1240
|
*/ |
|
1241
|
CMARK_EXPORT cmark_node *cmark_node_new_with_mem(cmark_node_type type, |
|
1242
|
cmark_mem *mem); |
|
1243
|
|
|
1244
|
/** Frees the memory allocated for a node and any children. |
|
1245
|
*/ |
|
1246
|
CMARK_EXPORT void cmark_node_free(cmark_node *node); |
|
1247
|
|
|
1248
|
/** |
|
1249
|
* ## Tree Traversal |
|
1250
|
*/ |
|
1251
|
|
|
1252
|
/** Returns the next node in the sequence after 'node', or NULL if |
|
1253
|
* there is none. |
|
1254
|
*/ |
|
1255
|
CMARK_EXPORT cmark_node *cmark_node_next(cmark_node *node); |
|
1256
|
|
|
1257
|
/** Returns the previous node in the sequence after 'node', or NULL if |
|
1258
|
* there is none. |
|
1259
|
*/ |
|
1260
|
CMARK_EXPORT cmark_node *cmark_node_previous(cmark_node *node); |
|
1261
|
|
|
1262
|
/** Returns the parent of 'node', or NULL if there is none. |
|
1263
|
*/ |
|
1264
|
CMARK_EXPORT cmark_node *cmark_node_parent(cmark_node *node); |
|
1265
|
|
|
1266
|
/** Returns the first child of 'node', or NULL if 'node' has no children. |
|
1267
|
*/ |
|
1268
|
CMARK_EXPORT cmark_node *cmark_node_first_child(cmark_node *node); |
|
1269
|
|
|
1270
|
/** Returns the last child of 'node', or NULL if 'node' has no children. |
|
1271
|
*/ |
|
1272
|
CMARK_EXPORT cmark_node *cmark_node_last_child(cmark_node *node); |
|
1273
|
|
|
1274
|
/** |
|
1275
|
* ## Iterator |
|
1276
|
* |
|
1277
|
* An iterator will walk through a tree of nodes, starting from a root |
|
1278
|
* node, returning one node at a time, together with information about |
|
1279
|
* whether the node is being entered or exited. The iterator will |
|
1280
|
* first descend to a child node, if there is one. When there is no |
|
1281
|
* child, the iterator will go to the next sibling. When there is no |
|
1282
|
* next sibling, the iterator will return to the parent (but with |
|
1283
|
* a 'cmark_event_type' of `CMARK_EVENT_EXIT`). The iterator will |
|
1284
|
* return `CMARK_EVENT_DONE` when it reaches the root node again. |
|
1285
|
* One natural application is an HTML renderer, where an `ENTER` event |
|
1286
|
* outputs an open tag and an `EXIT` event outputs a close tag. |
|
1287
|
* An iterator might also be used to transform an AST in some systematic |
|
1288
|
* way, for example, turning all level-3 headings into regular paragraphs. |
|
1289
|
* |
|
1290
|
* void |
|
1291
|
* usage_example(cmark_node *root) { |
|
1292
|
* cmark_event_type ev_type; |
|
1293
|
* cmark_iter *iter = cmark_iter_new(root); |
|
1294
|
* |
|
1295
|
* while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { |
|
1296
|
* cmark_node *cur = cmark_iter_get_node(iter); |
|
1297
|
* // Do something with `cur` and `ev_type` |
|
1298
|
* } |
|
1299
|
* |
|
1300
|
* cmark_iter_free(iter); |
|
1301
|
* } |
|
1302
|
* |
|
1303
|
* Iterators will never return `EXIT` events for leaf nodes, which are nodes |
|
1304
|
* of type: |
|
1305
|
* |
|
1306
|
* * CMARK_NODE_HTML_BLOCK |
|
1307
|
* * CMARK_NODE_THEMATIC_BREAK |
|
1308
|
* * CMARK_NODE_CODE_BLOCK |
|
1309
|
* * CMARK_NODE_TEXT |
|
1310
|
* * CMARK_NODE_SOFTBREAK |
|
1311
|
* * CMARK_NODE_LINEBREAK |
|
1312
|
* * CMARK_NODE_CODE |
|
1313
|
* * CMARK_NODE_HTML_INLINE |
|
1314
|
* |
|
1315
|
* Nodes must only be modified after an `EXIT` event, or an `ENTER` event for |
|
1316
|
* leaf nodes. |
|
1317
|
*/ |
|
1318
|
|
|
1319
|
typedef enum { |
|
1320
|
CMARK_EVENT_NONE, |
|
1321
|
CMARK_EVENT_DONE, |
|
1322
|
CMARK_EVENT_ENTER, |
|
1323
|
CMARK_EVENT_EXIT |
|
1324
|
} cmark_event_type; |
|
1325
|
|
|
1326
|
/** Creates a new iterator starting at 'root'. The current node and event |
|
1327
|
* type are undefined until 'cmark_iter_next' is called for the first time. |
|
1328
|
* The memory allocated for the iterator should be released using |
|
1329
|
* 'cmark_iter_free' when it is no longer needed. |
|
1330
|
*/ |
|
1331
|
CMARK_EXPORT |
|
1332
|
cmark_iter *cmark_iter_new(cmark_node *root); |
|
1333
|
|
|
1334
|
/** Frees the memory allocated for an iterator. |
|
1335
|
*/ |
|
1336
|
CMARK_EXPORT |
|
1337
|
void cmark_iter_free(cmark_iter *iter); |
|
1338
|
|
|
1339
|
/** Advances to the next node and returns the event type (`CMARK_EVENT_ENTER`, |
|
1340
|
* `CMARK_EVENT_EXIT` or `CMARK_EVENT_DONE`). |
|
1341
|
*/ |
|
1342
|
CMARK_EXPORT |
|
1343
|
cmark_event_type cmark_iter_next(cmark_iter *iter); |
|
1344
|
|
|
1345
|
/** Returns the current node. |
|
1346
|
*/ |
|
1347
|
CMARK_EXPORT |
|
1348
|
cmark_node *cmark_iter_get_node(cmark_iter *iter); |
|
1349
|
|
|
1350
|
/** Returns the current event type. |
|
1351
|
*/ |
|
1352
|
CMARK_EXPORT |
|
1353
|
cmark_event_type cmark_iter_get_event_type(cmark_iter *iter); |
|
1354
|
|
|
1355
|
/** Returns the root node. |
|
1356
|
*/ |
|
1357
|
CMARK_EXPORT |
|
1358
|
cmark_node *cmark_iter_get_root(cmark_iter *iter); |
|
1359
|
|
|
1360
|
/** Resets the iterator so that the current node is 'current' and |
|
1361
|
* the event type is 'event_type'. The new current node must be a |
|
1362
|
* descendant of the root node or the root node itself. |
|
1363
|
*/ |
|
1364
|
CMARK_EXPORT |
|
1365
|
void cmark_iter_reset(cmark_iter *iter, cmark_node *current, |
|
1366
|
cmark_event_type event_type); |
|
1367
|
|
|
1368
|
/** |
|
1369
|
* ## Accessors |
|
1370
|
*/ |
|
1371
|
|
|
1372
|
/** Returns the user data of 'node'. |
|
1373
|
*/ |
|
1374
|
CMARK_EXPORT void *cmark_node_get_user_data(cmark_node *node); |
|
1375
|
|
|
1376
|
/** Sets arbitrary user data for 'node'. Returns 1 on success, |
|
1377
|
* 0 on failure. |
|
1378
|
*/ |
|
1379
|
CMARK_EXPORT int cmark_node_set_user_data(cmark_node *node, void *user_data); |
|
1380
|
|
|
1381
|
/** Returns the type of 'node', or `CMARK_NODE_NONE` on error. |
|
1382
|
*/ |
|
1383
|
CMARK_EXPORT cmark_node_type cmark_node_get_type(cmark_node *node); |
|
1384
|
|
|
1385
|
/** Like 'cmark_node_get_type', but returns a string representation |
|
1386
|
of the type, or `"<unknown>"`. |
|
1387
|
*/ |
|
1388
|
CMARK_EXPORT |
|
1389
|
const char *cmark_node_get_type_string(cmark_node *node); |
|
1390
|
|
|
1391
|
/** Returns the string contents of 'node', or an empty |
|
1392
|
string if none is set. |
|
1393
|
*/ |
|
1394
|
CMARK_EXPORT const char *cmark_node_get_literal(cmark_node *node); |
|
1395
|
|
|
1396
|
/** Sets the string contents of 'node'. Returns 1 on success, |
|
1397
|
* 0 on failure. |
|
1398
|
*/ |
|
1399
|
CMARK_EXPORT int cmark_node_set_literal(cmark_node *node, const char *content); |
|
1400
|
|
|
1401
|
/** Returns the heading level of 'node', or 0 if 'node' is not a heading. |
|
1402
|
*/ |
|
1403
|
CMARK_EXPORT int cmark_node_get_heading_level(cmark_node *node); |
|
1404
|
|
|
1405
|
/* For backwards compatibility */ |
|
1406
|
#define cmark_node_get_header_level cmark_node_get_heading_level |
|
1407
|
#define cmark_node_set_header_level cmark_node_set_heading_level |
|
1408
|
|
|
1409
|
/** Sets the heading level of 'node', returning 1 on success and 0 on error. |
|
1410
|
*/ |
|
1411
|
CMARK_EXPORT int cmark_node_set_heading_level(cmark_node *node, int level); |
|
1412
|
|
|
1413
|
/** Returns the list type of 'node', or `CMARK_NO_LIST` if 'node' |
|
1414
|
* is not a list. |
|
1415
|
*/ |
|
1416
|
CMARK_EXPORT cmark_list_type cmark_node_get_list_type(cmark_node *node); |
|
1417
|
|
|
1418
|
/** Sets the list type of 'node', returning 1 on success and 0 on error. |
|
1419
|
*/ |
|
1420
|
CMARK_EXPORT int cmark_node_set_list_type(cmark_node *node, |
|
1421
|
cmark_list_type type); |
|
1422
|
|
|
1423
|
/** Returns the list delimiter type of 'node', or `CMARK_NO_DELIM` if 'node' |
|
1424
|
* is not a list. |
|
1425
|
*/ |
|
1426
|
CMARK_EXPORT cmark_delim_type cmark_node_get_list_delim(cmark_node *node); |
|
1427
|
|
|
1428
|
/** Sets the list delimiter type of 'node', returning 1 on success and 0 |
|
1429
|
* on error. |
|
1430
|
*/ |
|
1431
|
CMARK_EXPORT int cmark_node_set_list_delim(cmark_node *node, |
|
1432
|
cmark_delim_type delim); |
|
1433
|
|
|
1434
|
/** Returns starting number of 'node', if it is an ordered list, otherwise 0. |
|
1435
|
*/ |
|
1436
|
CMARK_EXPORT int cmark_node_get_list_start(cmark_node *node); |
|
1437
|
|
|
1438
|
/** Sets starting number of 'node', if it is an ordered list. Returns 1 |
|
1439
|
* on success, 0 on failure. |
|
1440
|
*/ |
|
1441
|
CMARK_EXPORT int cmark_node_set_list_start(cmark_node *node, int start); |
|
1442
|
|
|
1443
|
/** Returns 1 if 'node' is a tight list, 0 otherwise. |
|
1444
|
*/ |
|
1445
|
CMARK_EXPORT int cmark_node_get_list_tight(cmark_node *node); |
|
1446
|
|
|
1447
|
/** Sets the "tightness" of a list. Returns 1 on success, 0 on failure. |
|
1448
|
*/ |
|
1449
|
CMARK_EXPORT int cmark_node_set_list_tight(cmark_node *node, int tight); |
|
1450
|
|
|
1451
|
/** Returns the info string from a fenced code block. |
|
1452
|
*/ |
|
1453
|
CMARK_EXPORT const char *cmark_node_get_fence_info(cmark_node *node); |
|
1454
|
|
|
1455
|
/** Sets the info string in a fenced code block, returning 1 on |
|
1456
|
* success and 0 on failure. |
|
1457
|
*/ |
|
1458
|
CMARK_EXPORT int cmark_node_set_fence_info(cmark_node *node, const char *info); |
|
1459
|
|
|
1460
|
/** Returns the URL of a link or image 'node', or an empty string |
|
1461
|
if no URL is set. |
|
1462
|
*/ |
|
1463
|
CMARK_EXPORT const char *cmark_node_get_url(cmark_node *node); |
|
1464
|
|
|
1465
|
/** Sets the URL of a link or image 'node'. Returns 1 on success, |
|
1466
|
* 0 on failure. |
|
1467
|
*/ |
|
1468
|
CMARK_EXPORT int cmark_node_set_url(cmark_node *node, const char *url); |
|
1469
|
|
|
1470
|
/** Returns the title of a link or image 'node', or an empty |
|
1471
|
string if no title is set. |
|
1472
|
*/ |
|
1473
|
CMARK_EXPORT const char *cmark_node_get_title(cmark_node *node); |
|
1474
|
|
|
1475
|
/** Sets the title of a link or image 'node'. Returns 1 on success, |
|
1476
|
* 0 on failure. |
|
1477
|
*/ |
|
1478
|
CMARK_EXPORT int cmark_node_set_title(cmark_node *node, const char *title); |
|
1479
|
|
|
1480
|
/** Returns the literal "on enter" text for a custom 'node', or |
|
1481
|
an empty string if no on_enter is set. |
|
1482
|
*/ |
|
1483
|
CMARK_EXPORT const char *cmark_node_get_on_enter(cmark_node *node); |
|
1484
|
|
|
1485
|
/** Sets the literal text to render "on enter" for a custom 'node'. |
|
1486
|
Any children of the node will be rendered after this text. |
|
1487
|
Returns 1 on success 0 on failure. |
|
1488
|
*/ |
|
1489
|
CMARK_EXPORT int cmark_node_set_on_enter(cmark_node *node, |
|
1490
|
const char *on_enter); |
|
1491
|
|
|
1492
|
/** Returns the literal "on exit" text for a custom 'node', or |
|
1493
|
an empty string if no on_exit is set. |
|
1494
|
*/ |
|
1495
|
CMARK_EXPORT const char *cmark_node_get_on_exit(cmark_node *node); |
|
1496
|
|
|
1497
|
/** Sets the literal text to render "on exit" for a custom 'node'. |
|
1498
|
Any children of the node will be rendered before this text. |
|
1499
|
Returns 1 on success 0 on failure. |
|
1500
|
*/ |
|
1501
|
CMARK_EXPORT int cmark_node_set_on_exit(cmark_node *node, const char *on_exit); |
|
1502
|
|
|
1503
|
/** Returns the line on which 'node' begins. |
|
1504
|
*/ |
|
1505
|
CMARK_EXPORT int cmark_node_get_start_line(cmark_node *node); |
|
1506
|
|
|
1507
|
/** Returns the column at which 'node' begins. |
|
1508
|
*/ |
|
1509
|
CMARK_EXPORT int cmark_node_get_start_column(cmark_node *node); |
|
1510
|
|
|
1511
|
/** Returns the line on which 'node' ends. |
|
1512
|
*/ |
|
1513
|
CMARK_EXPORT int cmark_node_get_end_line(cmark_node *node); |
|
1514
|
|
|
1515
|
/** Returns the column at which 'node' ends. |
|
1516
|
*/ |
|
1517
|
CMARK_EXPORT int cmark_node_get_end_column(cmark_node *node); |
|
1518
|
|
|
1519
|
/** |
|
1520
|
* ## Tree Manipulation |
|
1521
|
*/ |
|
1522
|
|
|
1523
|
/** Unlinks a 'node', removing it from the tree, but not freeing its |
|
1524
|
* memory. (Use 'cmark_node_free' for that.) |
|
1525
|
*/ |
|
1526
|
CMARK_EXPORT void cmark_node_unlink(cmark_node *node); |
|
1527
|
|
|
1528
|
/** Inserts 'sibling' before 'node'. Returns 1 on success, 0 on failure. |
|
1529
|
*/ |
|
1530
|
CMARK_EXPORT int cmark_node_insert_before(cmark_node *node, |
|
1531
|
cmark_node *sibling); |
|
1532
|
|
|
1533
|
/** Inserts 'sibling' after 'node'. Returns 1 on success, 0 on failure. |
|
1534
|
*/ |
|
1535
|
CMARK_EXPORT int cmark_node_insert_after(cmark_node *node, cmark_node *sibling); |
|
1536
|
|
|
1537
|
/** Replaces 'oldnode' with 'newnode' and unlinks 'oldnode' (but does |
|
1538
|
* not free its memory). |
|
1539
|
* Returns 1 on success, 0 on failure. |
|
1540
|
*/ |
|
1541
|
CMARK_EXPORT int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode); |
|
1542
|
|
|
1543
|
/** Adds 'child' to the beginning of the children of 'node'. |
|
1544
|
* Returns 1 on success, 0 on failure. |
|
1545
|
*/ |
|
1546
|
CMARK_EXPORT int cmark_node_prepend_child(cmark_node *node, cmark_node *child); |
|
1547
|
|
|
1548
|
/** Adds 'child' to the end of the children of 'node'. |
|
1549
|
* Returns 1 on success, 0 on failure. |
|
1550
|
*/ |
|
1551
|
CMARK_EXPORT int cmark_node_append_child(cmark_node *node, cmark_node *child); |
|
1552
|
|
|
1553
|
/** Consolidates adjacent text nodes. |
|
1554
|
*/ |
|
1555
|
CMARK_EXPORT void cmark_consolidate_text_nodes(cmark_node *root); |
|
1556
|
|
|
1557
|
/** |
|
1558
|
* ## Parsing |
|
1559
|
* |
|
1560
|
* Simple interface: |
|
1561
|
* |
|
1562
|
* cmark_node *document = cmark_parse_document("Hello *world*", 13, |
|
1563
|
* CMARK_OPT_DEFAULT); |
|
1564
|
* |
|
1565
|
* Streaming interface: |
|
1566
|
* |
|
1567
|
* cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT); |
|
1568
|
* FILE *fp = fopen("myfile.md", "rb"); |
|
1569
|
* while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) { |
|
1570
|
* cmark_parser_feed(parser, buffer, bytes); |
|
1571
|
* if (bytes < sizeof(buffer)) { |
|
1572
|
* break; |
|
1573
|
* } |
|
1574
|
* } |
|
1575
|
* document = cmark_parser_finish(parser); |
|
1576
|
* cmark_parser_free(parser); |
|
1577
|
*/ |
|
1578
|
|
|
1579
|
/** Creates a new parser object. |
|
1580
|
*/ |
|
1581
|
CMARK_EXPORT |
|
1582
|
cmark_parser *cmark_parser_new(int options); |
|
1583
|
|
|
1584
|
/** Creates a new parser object with the given memory allocator |
|
1585
|
*/ |
|
1586
|
CMARK_EXPORT |
|
1587
|
cmark_parser *cmark_parser_new_with_mem(int options, cmark_mem *mem); |
|
1588
|
|
|
1589
|
/** Frees memory allocated for a parser object. |
|
1590
|
*/ |
|
1591
|
CMARK_EXPORT |
|
1592
|
void cmark_parser_free(cmark_parser *parser); |
|
1593
|
|
|
1594
|
/** Feeds a string of length 'len' to 'parser'. |
|
1595
|
*/ |
|
1596
|
CMARK_EXPORT |
|
1597
|
void cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len); |
|
1598
|
|
|
1599
|
/** Finish parsing and return a pointer to a tree of nodes. |
|
1600
|
*/ |
|
1601
|
CMARK_EXPORT |
|
1602
|
cmark_node *cmark_parser_finish(cmark_parser *parser); |
|
1603
|
|
|
1604
|
/** Parse a CommonMark document in 'buffer' of length 'len'. |
|
1605
|
* Returns a pointer to a tree of nodes. The memory allocated for |
|
1606
|
* the node tree should be released using 'cmark_node_free' |
|
1607
|
* when it is no longer needed. |
|
1608
|
*/ |
|
1609
|
CMARK_EXPORT |
|
1610
|
cmark_node *cmark_parse_document(const char *buffer, size_t len, int options); |
|
1611
|
|
|
1612
|
/** Parse a CommonMark document in file 'f', returning a pointer to |
|
1613
|
* a tree of nodes. The memory allocated for the node tree should be |
|
1614
|
* released using 'cmark_node_free' when it is no longer needed. |
|
1615
|
*/ |
|
1616
|
CMARK_EXPORT |
|
1617
|
cmark_node *cmark_parse_file(FILE *f, int options); |
|
1618
|
|
|
1619
|
/** |
|
1620
|
* ## Rendering |
|
1621
|
*/ |
|
1622
|
|
|
1623
|
/** Render a 'node' tree as XML. It is the caller's responsibility |
|
1624
|
* to free the returned buffer. |
|
1625
|
*/ |
|
1626
|
CMARK_EXPORT |
|
1627
|
char *cmark_render_xml(cmark_node *root, int options); |
|
1628
|
|
|
1629
|
/** Render a 'node' tree as an HTML fragment. It is up to the user |
|
1630
|
* to add an appropriate header and footer. It is the caller's |
|
1631
|
* responsibility to free the returned buffer. |
|
1632
|
*/ |
|
1633
|
CMARK_EXPORT |
|
1634
|
char *cmark_render_html(cmark_node *root, int options); |
|
1635
|
|
|
1636
|
/** Render a 'node' tree as a groff man page, without the header. |
|
1637
|
* It is the caller's responsibility to free the returned buffer. |
|
1638
|
*/ |
|
1639
|
CMARK_EXPORT |
|
1640
|
char *cmark_render_man(cmark_node *root, int options, int width); |
|
1641
|
|
|
1642
|
/** Render a 'node' tree as a commonmark document. |
|
1643
|
* It is the caller's responsibility to free the returned buffer. |
|
1644
|
*/ |
|
1645
|
CMARK_EXPORT |
|
1646
|
char *cmark_render_commonmark(cmark_node *root, int options, int width); |
|
1647
|
|
|
1648
|
/** Render a 'node' tree as a LaTeX document. |
|
1649
|
* It is the caller's responsibility to free the returned buffer. |
|
1650
|
*/ |
|
1651
|
CMARK_EXPORT |
|
1652
|
char *cmark_render_latex(cmark_node *root, int options, int width); |
|
1653
|
|
|
1654
|
/** |
|
1655
|
* ## Options |
|
1656
|
*/ |
|
1657
|
|
|
1658
|
/** Default options. |
|
1659
|
*/ |
|
1660
|
#define CMARK_OPT_DEFAULT 0 |
|
1661
|
|
|
1662
|
/** |
|
1663
|
* ### Options affecting rendering |
|
1664
|
*/ |
|
1665
|
|
|
1666
|
/** Include a `data-sourcepos` attribute on all block elements. |
|
1667
|
*/ |
|
1668
|
#define CMARK_OPT_SOURCEPOS (1 << 1) |
|
1669
|
|
|
1670
|
/** Render `softbreak` elements as hard line breaks. |
|
1671
|
*/ |
|
1672
|
#define CMARK_OPT_HARDBREAKS (1 << 2) |
|
1673
|
|
|
1674
|
/** Suppress raw HTML and unsafe links (`javascript:`, `vbscript:`, |
|
1675
|
* `file:`, and `data:`, except for `image/png`, `image/gif`, |
|
1676
|
* `image/jpeg`, or `image/webp` mime types). Raw HTML is replaced |
|
1677
|
* by a placeholder HTML comment. Unsafe links are replaced by |
|
1678
|
* empty strings. |
|
1679
|
*/ |
|
1680
|
#define CMARK_OPT_SAFE (1 << 3) |
|
1681
|
|
|
1682
|
/** Render `softbreak` elements as spaces. |
|
1683
|
*/ |
|
1684
|
#define CMARK_OPT_NOBREAKS (1 << 4) |
|
1685
|
|
|
1686
|
/** |
|
1687
|
* ### Options affecting parsing |
|
1688
|
*/ |
|
1689
|
|
|
1690
|
/** Normalize tree by consolidating adjacent text nodes. |
|
1691
|
*/ |
|
1692
|
#define CMARK_OPT_NORMALIZE (1 << 8) |
|
1693
|
|
|
1694
|
/** Validate UTF-8 in the input before parsing, replacing illegal |
|
1695
|
* sequences with the replacement character U+FFFD. |
|
1696
|
*/ |
|
1697
|
#define CMARK_OPT_VALIDATE_UTF8 (1 << 9) |
|
1698
|
|
|
1699
|
/** Convert straight quotes to curly, --- to em dashes, -- to en dashes. |
|
1700
|
*/ |
|
1701
|
#define CMARK_OPT_SMART (1 << 10) |
|
1702
|
|
|
1703
|
/** |
|
1704
|
* ## Version information |
|
1705
|
*/ |
|
1706
|
|
|
1707
|
/** The library version as integer for runtime checks. Also available as |
|
1708
|
* macro CMARK_VERSION for compile time checks. |
|
1709
|
* |
|
1710
|
* * Bits 16-23 contain the major version. |
|
1711
|
* * Bits 8-15 contain the minor version. |
|
1712
|
* * Bits 0-7 contain the patchlevel. |
|
1713
|
* |
|
1714
|
* In hexadecimal format, the number 0x010203 represents version 1.2.3. |
|
1715
|
*/ |
|
1716
|
CMARK_EXPORT |
|
1717
|
int cmark_version(void); |
|
1718
|
|
|
1719
|
/** The library version string for runtime checks. Also available as |
|
1720
|
* macro CMARK_VERSION_STRING for compile time checks. |
|
1721
|
*/ |
|
1722
|
CMARK_EXPORT |
|
1723
|
const char *cmark_version_string(void); |
|
1724
|
|
|
1725
|
/** # AUTHORS |
|
1726
|
* |
|
1727
|
* John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer. |
|
1728
|
*/ |
|
1729
|
|
|
1730
|
#ifndef CMARK_NO_SHORT_NAMES |
|
1731
|
#define NODE_DOCUMENT CMARK_NODE_DOCUMENT |
|
1732
|
#define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE |
|
1733
|
#define NODE_LIST CMARK_NODE_LIST |
|
1734
|
#define NODE_ITEM CMARK_NODE_ITEM |
|
1735
|
#define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK |
|
1736
|
#define NODE_HTML_BLOCK CMARK_NODE_HTML_BLOCK |
|
1737
|
#define NODE_CUSTOM_BLOCK CMARK_NODE_CUSTOM_BLOCK |
|
1738
|
#define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH |
|
1739
|
#define NODE_HEADING CMARK_NODE_HEADING |
|
1740
|
#define NODE_HEADER CMARK_NODE_HEADER |
|
1741
|
#define NODE_THEMATIC_BREAK CMARK_NODE_THEMATIC_BREAK |
|
1742
|
#define NODE_HRULE CMARK_NODE_HRULE |
|
1743
|
#define NODE_TEXT CMARK_NODE_TEXT |
|
1744
|
#define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK |
|
1745
|
#define NODE_LINEBREAK CMARK_NODE_LINEBREAK |
|
1746
|
#define NODE_CODE CMARK_NODE_CODE |
|
1747
|
#define NODE_HTML_INLINE CMARK_NODE_HTML_INLINE |
|
1748
|
#define NODE_CUSTOM_INLINE CMARK_NODE_CUSTOM_INLINE |
|
1749
|
#define NODE_EMPH CMARK_NODE_EMPH |
|
1750
|
#define NODE_STRONG CMARK_NODE_STRONG |
|
1751
|
#define NODE_LINK CMARK_NODE_LINK |
|
1752
|
#define NODE_IMAGE CMARK_NODE_IMAGE |
|
1753
|
#define BULLET_LIST CMARK_BULLET_LIST |
|
1754
|
#define ORDERED_LIST CMARK_ORDERED_LIST |
|
1755
|
#define PERIOD_DELIM CMARK_PERIOD_DELIM |
|
1756
|
#define PAREN_DELIM CMARK_PAREN_DELIM |
|
1757
|
#endif |
|
1758
|
|
|
1759
|
#ifdef __cplusplus |
|
1760
|
} |
|
1761
|
#endif |
|
1762
|
|
|
1763
|
#endif |
|
1764
|
|
|
1765
|
#ifndef CMARK_EXPORT_H |
|
1766
|
#define CMARK_EXPORT_H |
|
1767
|
|
|
1768
|
#ifdef CMARK_STATIC_DEFINE |
|
1769
|
# define CMARK_EXPORT |
|
1770
|
# define CMARK_NO_EXPORT |
|
1771
|
#else |
|
1772
|
# ifndef CMARK_EXPORT |
|
1773
|
# ifdef libcmark_EXPORTS |
|
1774
|
/* We are building this library */ |
|
1775
|
# define CMARK_EXPORT __attribute__((visibility("default"))) |
|
1776
|
# else |
|
1777
|
/* We are using this library */ |
|
1778
|
# define CMARK_EXPORT __attribute__((visibility("default"))) |
|
1779
|
# endif |
|
1780
|
# endif |
|
1781
|
|
|
1782
|
# ifndef CMARK_NO_EXPORT |
|
1783
|
# define CMARK_NO_EXPORT __attribute__((visibility("hidden"))) |
|
1784
|
# endif |
|
1785
|
#endif |
|
1786
|
|
|
1787
|
#ifndef CMARK_DEPRECATED |
|
1788
|
# define CMARK_DEPRECATED __attribute__ ((__deprecated__)) |
|
1789
|
#endif |
|
1790
|
|
|
1791
|
#ifndef CMARK_DEPRECATED_EXPORT |
|
1792
|
# define CMARK_DEPRECATED_EXPORT CMARK_EXPORT CMARK_DEPRECATED |
|
1793
|
#endif |
|
1794
|
|
|
1795
|
#ifndef CMARK_DEPRECATED_NO_EXPORT |
|
1796
|
# define CMARK_DEPRECATED_NO_EXPORT CMARK_NO_EXPORT CMARK_DEPRECATED |
|
1797
|
#endif |
|
1798
|
|
|
1799
|
#if 0 /* DEFINE_NO_DEPRECATED */ |
|
1800
|
# ifndef CMARK_NO_DEPRECATED |
|
1801
|
# define CMARK_NO_DEPRECATED |
|
1802
|
# endif |
|
1803
|
#endif |
|
1804
|
|
|
1805
|
#endif |
|
1806
|
#ifndef CMARK_VERSION_H |
|
1807
|
#define CMARK_VERSION_H |
|
1808
|
|
|
1809
|
#define CMARK_VERSION ((0 << 16) | (27 << 8) | 1) |
|
1810
|
#define CMARK_VERSION_STRING "0.27.1" |
|
1811
|
|
|
1812
|
#endif |
|
1813
|
|
|
1814
|
|
|
1815
|
#ifndef CMARK_AST_H |
|
1816
|
#define CMARK_AST_H |
|
1817
|
|
|
1818
|
#include <stdio.h> |
|
1819
|
|
|
1820
|
#ifdef __cplusplus |
|
1821
|
extern "C" { |
|
1822
|
#endif |
|
1823
|
|
|
1824
|
#define MAX_LINK_LABEL_LENGTH 1000 |
|
1825
|
|
|
1826
|
struct cmark_parser { |
|
1827
|
struct cmark_mem *mem; |
|
1828
|
struct cmark_reference_map *refmap; |
|
1829
|
struct cmark_node *root; |
|
1830
|
struct cmark_node *current; |
|
1831
|
int line_number; |
|
1832
|
bufsize_t offset; |
|
1833
|
bufsize_t column; |
|
1834
|
bufsize_t first_nonspace; |
|
1835
|
bufsize_t first_nonspace_column; |
|
1836
|
int indent; |
|
1837
|
bool blank; |
|
1838
|
bool partially_consumed_tab; |
|
1839
|
cmark_strbuf curline; |
|
1840
|
bufsize_t last_line_length; |
|
1841
|
cmark_strbuf linebuf; |
|
1842
|
int options; |
|
1843
|
bool last_buffer_ended_with_cr; |
|
1844
|
}; |
|
1845
|
|
|
1846
|
#ifdef __cplusplus |
|
1847
|
} |
|
1848
|
#endif |
|
1849
|
|
|
1850
|
#endif |
|
1851
|
|
|
1852
|
|
|
1853
|
#ifndef CMARK_REFERENCES_H |
|
1854
|
#define CMARK_REFERENCES_H |
|
1855
|
|
|
1856
|
|
|
1857
|
#ifdef __cplusplus |
|
1858
|
extern "C" { |
|
1859
|
#endif |
|
1860
|
|
|
1861
|
#define REFMAP_SIZE 16 |
|
1862
|
|
|
1863
|
struct cmark_reference { |
|
1864
|
struct cmark_reference *next; |
|
1865
|
unsigned char *label; |
|
1866
|
cmark_chunk url; |
|
1867
|
cmark_chunk title; |
|
1868
|
unsigned int hash; |
|
1869
|
}; |
|
1870
|
|
|
1871
|
typedef struct cmark_reference cmark_reference; |
|
1872
|
|
|
1873
|
struct cmark_reference_map { |
|
1874
|
cmark_mem *mem; |
|
1875
|
cmark_reference *table[REFMAP_SIZE]; |
|
1876
|
}; |
|
1877
|
|
|
1878
|
typedef struct cmark_reference_map cmark_reference_map; |
|
1879
|
|
|
1880
|
cmark_reference_map *cmark_reference_map_new(cmark_mem *mem); |
|
1881
|
void cmark_reference_map_free(cmark_reference_map *map); |
|
1882
|
cmark_reference *cmark_reference_lookup(cmark_reference_map *map, |
|
1883
|
cmark_chunk *label); |
|
1884
|
extern void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label, |
|
1885
|
cmark_chunk *url, cmark_chunk *title); |
|
1886
|
|
|
1887
|
#ifdef __cplusplus |
|
1888
|
} |
|
1889
|
#endif |
|
1890
|
|
|
1891
|
#endif |
|
1892
|
|
|
1893
|
#ifndef CMARK_UTF8_H |
|
1894
|
#define CMARK_UTF8_H |
|
1895
|
|
|
1896
|
#include <stdint.h> |
|
1897
|
|
|
1898
|
#ifdef __cplusplus |
|
1899
|
extern "C" { |
|
1900
|
#endif |
|
1901
|
|
|
1902
|
void cmark_utf8proc_case_fold(cmark_strbuf *dest, const uint8_t *str, |
|
1903
|
bufsize_t len); |
|
1904
|
void cmark_utf8proc_encode_char(int32_t uc, cmark_strbuf *buf); |
|
1905
|
int cmark_utf8proc_iterate(const uint8_t *str, bufsize_t str_len, int32_t *dst); |
|
1906
|
void cmark_utf8proc_check(cmark_strbuf *dest, const uint8_t *line, |
|
1907
|
bufsize_t size); |
|
1908
|
int cmark_utf8proc_is_space(int32_t uc); |
|
1909
|
int cmark_utf8proc_is_punctuation(int32_t uc); |
|
1910
|
|
|
1911
|
#ifdef __cplusplus |
|
1912
|
} |
|
1913
|
#endif |
|
1914
|
|
|
1915
|
#endif |
|
1916
|
|
|
1917
|
|
|
1918
|
#ifndef CMARK_INLINES_H |
|
1919
|
#define CMARK_INLINES_H |
|
1920
|
|
|
1921
|
#ifdef __cplusplus |
|
1922
|
extern "C" { |
|
1923
|
#endif |
|
1924
|
|
|
1925
|
cmark_chunk cmark_clean_url(cmark_mem *mem, cmark_chunk *url); |
|
1926
|
cmark_chunk cmark_clean_title(cmark_mem *mem, cmark_chunk *title); |
|
1927
|
|
|
1928
|
void cmark_parse_inlines(cmark_mem *mem, cmark_node *parent, |
|
1929
|
cmark_reference_map *refmap, int options); |
|
1930
|
|
|
1931
|
bufsize_t cmark_parse_reference_inline(cmark_mem *mem, cmark_strbuf *input, |
|
1932
|
cmark_reference_map *refmap); |
|
1933
|
|
|
1934
|
#ifdef __cplusplus |
|
1935
|
} |
|
1936
|
#endif |
|
1937
|
|
|
1938
|
#endif |
|
1939
|
|
|
1940
|
|
|
1941
|
#ifdef __cplusplus |
|
1942
|
extern "C" { |
|
1943
|
#endif |
|
1944
|
|
|
1945
|
bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c, |
|
1946
|
bufsize_t offset); |
|
1947
|
bufsize_t _scan_scheme(const unsigned char *p); |
|
1948
|
bufsize_t _scan_autolink_uri(const unsigned char *p); |
|
1949
|
bufsize_t _scan_autolink_email(const unsigned char *p); |
|
1950
|
bufsize_t _scan_html_tag(const unsigned char *p); |
|
1951
|
bufsize_t _scan_html_block_start(const unsigned char *p); |
|
1952
|
bufsize_t _scan_html_block_start_7(const unsigned char *p); |
|
1953
|
bufsize_t _scan_html_block_end_1(const unsigned char *p); |
|
1954
|
bufsize_t _scan_html_block_end_2(const unsigned char *p); |
|
1955
|
bufsize_t _scan_html_block_end_3(const unsigned char *p); |
|
1956
|
bufsize_t _scan_html_block_end_4(const unsigned char *p); |
|
1957
|
bufsize_t _scan_html_block_end_5(const unsigned char *p); |
|
1958
|
bufsize_t _scan_link_title(const unsigned char *p); |
|
1959
|
bufsize_t _scan_spacechars(const unsigned char *p); |
|
1960
|
bufsize_t _scan_atx_heading_start(const unsigned char *p); |
|
1961
|
bufsize_t _scan_setext_heading_line(const unsigned char *p); |
|
1962
|
bufsize_t _scan_thematic_break(const unsigned char *p); |
|
1963
|
bufsize_t _scan_open_code_fence(const unsigned char *p); |
|
1964
|
bufsize_t _scan_close_code_fence(const unsigned char *p); |
|
1965
|
bufsize_t _scan_entity(const unsigned char *p); |
|
1966
|
bufsize_t _scan_dangerous_url(const unsigned char *p); |
|
1967
|
|
|
1968
|
#define scan_scheme(c, n) _scan_at(&_scan_scheme, c, n) |
|
1969
|
#define scan_autolink_uri(c, n) _scan_at(&_scan_autolink_uri, c, n) |
|
1970
|
#define scan_autolink_email(c, n) _scan_at(&_scan_autolink_email, c, n) |
|
1971
|
#define scan_html_tag(c, n) _scan_at(&_scan_html_tag, c, n) |
|
1972
|
#define scan_html_block_start(c, n) _scan_at(&_scan_html_block_start, c, n) |
|
1973
|
#define scan_html_block_start_7(c, n) _scan_at(&_scan_html_block_start_7, c, n) |
|
1974
|
#define scan_html_block_end_1(c, n) _scan_at(&_scan_html_block_end_1, c, n) |
|
1975
|
#define scan_html_block_end_2(c, n) _scan_at(&_scan_html_block_end_2, c, n) |
|
1976
|
#define scan_html_block_end_3(c, n) _scan_at(&_scan_html_block_end_3, c, n) |
|
1977
|
#define scan_html_block_end_4(c, n) _scan_at(&_scan_html_block_end_4, c, n) |
|
1978
|
#define scan_html_block_end_5(c, n) _scan_at(&_scan_html_block_end_5, c, n) |
|
1979
|
#define scan_link_title(c, n) _scan_at(&_scan_link_title, c, n) |
|
1980
|
#define scan_spacechars(c, n) _scan_at(&_scan_spacechars, c, n) |
|
1981
|
#define scan_atx_heading_start(c, n) _scan_at(&_scan_atx_heading_start, c, n) |
|
1982
|
#define scan_setext_heading_line(c, n) \ |
|
1983
|
_scan_at(&_scan_setext_heading_line, c, n) |
|
1984
|
#define scan_thematic_break(c, n) _scan_at(&_scan_thematic_break, c, n) |
|
1985
|
#define scan_open_code_fence(c, n) _scan_at(&_scan_open_code_fence, c, n) |
|
1986
|
#define scan_close_code_fence(c, n) _scan_at(&_scan_close_code_fence, c, n) |
|
1987
|
#define scan_entity(c, n) _scan_at(&_scan_entity, c, n) |
|
1988
|
#define scan_dangerous_url(c, n) _scan_at(&_scan_dangerous_url, c, n) |
|
1989
|
|
|
1990
|
#ifdef __cplusplus |
|
1991
|
} |
|
1992
|
#endif |
|
1993
|
|
|
1994
|
|
|
1995
|
#ifndef CMARK_ITERATOR_H |
|
1996
|
#define CMARK_ITERATOR_H |
|
1997
|
|
|
1998
|
#ifdef __cplusplus |
|
1999
|
extern "C" { |
|
2000
|
#endif |
|
2001
|
|
|
2002
|
|
|
2003
|
typedef struct { |
|
2004
|
cmark_event_type ev_type; |
|
2005
|
cmark_node *node; |
|
2006
|
} cmark_iter_state; |
|
2007
|
|
|
2008
|
struct cmark_iter { |
|
2009
|
cmark_mem *mem; |
|
2010
|
cmark_node *root; |
|
2011
|
cmark_iter_state cur; |
|
2012
|
cmark_iter_state next; |
|
2013
|
}; |
|
2014
|
|
|
2015
|
#ifdef __cplusplus |
|
2016
|
} |
|
2017
|
#endif |
|
2018
|
|
|
2019
|
#endif |
|
2020
|
|