| 1 |
.TH cmark 3 "September 24, 2021" "cmark 0.30.2" "Library Functions Manual" |
| 2 |
.SH |
| 3 |
NAME |
| 4 |
.PP |
| 5 |
\f[B]cmark\f[] \- CommonMark parsing, manipulating, and rendering |
| 6 |
|
| 7 |
.SH |
| 8 |
DESCRIPTION |
| 9 |
.SS |
| 10 |
Simple Interface |
| 11 |
|
| 12 |
.PP |
| 13 |
\fIchar *\f[] \fBcmark_markdown_to_html\f[](\fIconst char *text\f[], \fIsize_t len\f[], \fIint options\f[]) |
| 14 |
|
| 15 |
.PP |
| 16 |
Convert \f[I]text\f[] (assumed to be a UTF\-8 encoded string with length |
| 17 |
\f[I]len\f[]) from CommonMark Markdown to HTML, returning a |
| 18 |
null\-terminated, UTF\-8\-encoded string. It is the caller's |
| 19 |
responsibility to free the returned buffer. |
| 20 |
|
| 21 |
.SS |
| 22 |
Node Structure |
| 23 |
|
| 24 |
.PP |
| 25 |
.nf |
| 26 |
\fC |
| 27 |
.RS 0n |
| 28 |
typedef enum { |
| 29 |
/* Error status */ |
| 30 |
CMARK_NODE_NONE, |
| 31 |
|
| 32 |
/* Block */ |
| 33 |
CMARK_NODE_DOCUMENT, |
| 34 |
CMARK_NODE_BLOCK_QUOTE, |
| 35 |
CMARK_NODE_LIST, |
| 36 |
CMARK_NODE_ITEM, |
| 37 |
CMARK_NODE_CODE_BLOCK, |
| 38 |
CMARK_NODE_HTML_BLOCK, |
| 39 |
CMARK_NODE_CUSTOM_BLOCK, |
| 40 |
CMARK_NODE_PARAGRAPH, |
| 41 |
CMARK_NODE_HEADING, |
| 42 |
CMARK_NODE_THEMATIC_BREAK, |
| 43 |
|
| 44 |
CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT, |
| 45 |
CMARK_NODE_LAST_BLOCK = CMARK_NODE_THEMATIC_BREAK, |
| 46 |
|
| 47 |
/* Inline */ |
| 48 |
CMARK_NODE_TEXT, |
| 49 |
CMARK_NODE_SOFTBREAK, |
| 50 |
CMARK_NODE_LINEBREAK, |
| 51 |
CMARK_NODE_CODE, |
| 52 |
CMARK_NODE_HTML_INLINE, |
| 53 |
CMARK_NODE_CUSTOM_INLINE, |
| 54 |
CMARK_NODE_EMPH, |
| 55 |
CMARK_NODE_STRONG, |
| 56 |
CMARK_NODE_LINK, |
| 57 |
CMARK_NODE_IMAGE, |
| 58 |
|
| 59 |
CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT, |
| 60 |
CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE |
| 61 |
} cmark_node_type; |
| 62 |
.RE |
| 63 |
\f[] |
| 64 |
.fi |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
.PP |
| 69 |
.nf |
| 70 |
\fC |
| 71 |
.RS 0n |
| 72 |
typedef enum { |
| 73 |
CMARK_NO_LIST, |
| 74 |
CMARK_BULLET_LIST, |
| 75 |
CMARK_ORDERED_LIST |
| 76 |
} cmark_list_type; |
| 77 |
.RE |
| 78 |
\f[] |
| 79 |
.fi |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
.PP |
| 84 |
.nf |
| 85 |
\fC |
| 86 |
.RS 0n |
| 87 |
typedef enum { |
| 88 |
CMARK_NO_DELIM, |
| 89 |
CMARK_PERIOD_DELIM, |
| 90 |
CMARK_PAREN_DELIM |
| 91 |
} cmark_delim_type; |
| 92 |
.RE |
| 93 |
\f[] |
| 94 |
.fi |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
.SS |
| 99 |
Custom memory allocator support |
| 100 |
|
| 101 |
.PP |
| 102 |
.nf |
| 103 |
\fC |
| 104 |
.RS 0n |
| 105 |
typedef struct cmark_mem { |
| 106 |
void *(*calloc)(size_t, size_t); |
| 107 |
void *(*realloc)(void *, size_t); |
| 108 |
void (*free)(void *); |
| 109 |
} cmark_mem; |
| 110 |
.RE |
| 111 |
\f[] |
| 112 |
.fi |
| 113 |
|
| 114 |
.PP |
| 115 |
Defines the memory allocation functions to be used by CMark when parsing |
| 116 |
and allocating a document tree |
| 117 |
|
| 118 |
.PP |
| 119 |
\fIcmark_mem *\f[] \fBcmark_get_default_mem_allocator\f[](\fI\f[]) |
| 120 |
|
| 121 |
.PP |
| 122 |
Returns a pointer to the default memory allocator. |
| 123 |
|
| 124 |
.SS |
| 125 |
Creating and Destroying Nodes |
| 126 |
|
| 127 |
.PP |
| 128 |
\fIcmark_node *\f[] \fBcmark_node_new\f[](\fIcmark_node_type type\f[]) |
| 129 |
|
| 130 |
.PP |
| 131 |
Creates a new node of type \f[I]type\f[]. Note that the node may have |
| 132 |
other required properties, which it is the caller's responsibility to |
| 133 |
assign. |
| 134 |
|
| 135 |
.PP |
| 136 |
\fIcmark_node *\f[] \fBcmark_node_new_with_mem\f[](\fIcmark_node_type type\f[], \fIcmark_mem *mem\f[]) |
| 137 |
|
| 138 |
.PP |
| 139 |
Same as \f[C]cmark_node_new\f[], but explicitly listing the memory |
| 140 |
allocator used to allocate the node. Note: be sure to use the same |
| 141 |
allocator for every node in a tree, or bad things can happen. |
| 142 |
|
| 143 |
.PP |
| 144 |
\fIvoid\f[] \fBcmark_node_free\f[](\fIcmark_node *node\f[]) |
| 145 |
|
| 146 |
.PP |
| 147 |
Frees the memory allocated for a node and any children. |
| 148 |
|
| 149 |
.SS |
| 150 |
Tree Traversal |
| 151 |
|
| 152 |
.PP |
| 153 |
\fIcmark_node *\f[] \fBcmark_node_next\f[](\fIcmark_node *node\f[]) |
| 154 |
|
| 155 |
.PP |
| 156 |
Returns the next node in the sequence after \f[I]node\f[], or NULL if |
| 157 |
there is none. |
| 158 |
|
| 159 |
.PP |
| 160 |
\fIcmark_node *\f[] \fBcmark_node_previous\f[](\fIcmark_node *node\f[]) |
| 161 |
|
| 162 |
.PP |
| 163 |
Returns the previous node in the sequence after \f[I]node\f[], or NULL |
| 164 |
if there is none. |
| 165 |
|
| 166 |
.PP |
| 167 |
\fIcmark_node *\f[] \fBcmark_node_parent\f[](\fIcmark_node *node\f[]) |
| 168 |
|
| 169 |
.PP |
| 170 |
Returns the parent of \f[I]node\f[], or NULL if there is none. |
| 171 |
|
| 172 |
.PP |
| 173 |
\fIcmark_node *\f[] \fBcmark_node_first_child\f[](\fIcmark_node *node\f[]) |
| 174 |
|
| 175 |
.PP |
| 176 |
Returns the first child of \f[I]node\f[], or NULL if \f[I]node\f[] has |
| 177 |
no children. |
| 178 |
|
| 179 |
.PP |
| 180 |
\fIcmark_node *\f[] \fBcmark_node_last_child\f[](\fIcmark_node *node\f[]) |
| 181 |
|
| 182 |
.PP |
| 183 |
Returns the last child of \f[I]node\f[], or NULL if \f[I]node\f[] has no |
| 184 |
children. |
| 185 |
|
| 186 |
.SS |
| 187 |
Iterator |
| 188 |
.PP |
| 189 |
An iterator will walk through a tree of nodes, starting from a root |
| 190 |
node, returning one node at a time, together with information about |
| 191 |
whether the node is being entered or exited. The iterator will first |
| 192 |
descend to a child node, if there is one. When there is no child, the |
| 193 |
iterator will go to the next sibling. When there is no next sibling, the |
| 194 |
iterator will return to the parent (but with a \f[I]cmark_event_type\f[] |
| 195 |
of \f[C]CMARK_EVENT_EXIT\f[]). The iterator will return |
| 196 |
\f[C]CMARK_EVENT_DONE\f[] when it reaches the root node again. One |
| 197 |
natural application is an HTML renderer, where an \f[C]ENTER\f[] event |
| 198 |
outputs an open tag and an \f[C]EXIT\f[] event outputs a close tag. An |
| 199 |
iterator might also be used to transform an AST in some systematic way, |
| 200 |
for example, turning all level\-3 headings into regular paragraphs. |
| 201 |
.IP |
| 202 |
.nf |
| 203 |
\f[C] |
| 204 |
void |
| 205 |
usage_example(cmark_node *root) { |
| 206 |
cmark_event_type ev_type; |
| 207 |
cmark_iter *iter = cmark_iter_new(root); |
| 208 |
|
| 209 |
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { |
| 210 |
cmark_node *cur = cmark_iter_get_node(iter); |
| 211 |
// Do something with `cur` and `ev_type` |
| 212 |
} |
| 213 |
|
| 214 |
cmark_iter_free(iter); |
| 215 |
} |
| 216 |
\f[] |
| 217 |
.fi |
| 218 |
.PP |
| 219 |
Iterators will never return \f[C]EXIT\f[] events for leaf nodes, which |
| 220 |
are nodes of type: |
| 221 |
.IP \[bu] 2 |
| 222 |
CMARK_NODE_HTML_BLOCK |
| 223 |
.IP \[bu] 2 |
| 224 |
CMARK_NODE_THEMATIC_BREAK |
| 225 |
.IP \[bu] 2 |
| 226 |
CMARK_NODE_CODE_BLOCK |
| 227 |
.IP \[bu] 2 |
| 228 |
CMARK_NODE_TEXT |
| 229 |
.IP \[bu] 2 |
| 230 |
CMARK_NODE_SOFTBREAK |
| 231 |
.IP \[bu] 2 |
| 232 |
CMARK_NODE_LINEBREAK |
| 233 |
.IP \[bu] 2 |
| 234 |
CMARK_NODE_CODE |
| 235 |
.IP \[bu] 2 |
| 236 |
CMARK_NODE_HTML_INLINE |
| 237 |
.PP |
| 238 |
Nodes must only be modified after an \f[C]EXIT\f[] event, or an |
| 239 |
\f[C]ENTER\f[] event for leaf nodes. |
| 240 |
|
| 241 |
.PP |
| 242 |
.nf |
| 243 |
\fC |
| 244 |
.RS 0n |
| 245 |
typedef enum { |
| 246 |
CMARK_EVENT_NONE, |
| 247 |
CMARK_EVENT_DONE, |
| 248 |
CMARK_EVENT_ENTER, |
| 249 |
CMARK_EVENT_EXIT |
| 250 |
} cmark_event_type; |
| 251 |
.RE |
| 252 |
\f[] |
| 253 |
.fi |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
.PP |
| 258 |
\fIcmark_iter *\f[] \fBcmark_iter_new\f[](\fIcmark_node *root\f[]) |
| 259 |
|
| 260 |
.PP |
| 261 |
Creates a new iterator starting at \f[I]root\f[]. The current node and |
| 262 |
event type are undefined until \f[I]cmark_iter_next\f[] is called for |
| 263 |
the first time. The memory allocated for the iterator should be released |
| 264 |
using \f[I]cmark_iter_free\f[] when it is no longer needed. |
| 265 |
|
| 266 |
.PP |
| 267 |
\fIvoid\f[] \fBcmark_iter_free\f[](\fIcmark_iter *iter\f[]) |
| 268 |
|
| 269 |
.PP |
| 270 |
Frees the memory allocated for an iterator. |
| 271 |
|
| 272 |
.PP |
| 273 |
\fIcmark_event_type\f[] \fBcmark_iter_next\f[](\fIcmark_iter *iter\f[]) |
| 274 |
|
| 275 |
.PP |
| 276 |
Advances to the next node and returns the event type |
| 277 |
(\f[C]CMARK_EVENT_ENTER\f[], \f[C]CMARK_EVENT_EXIT\f[] or |
| 278 |
\f[C]CMARK_EVENT_DONE\f[]). |
| 279 |
|
| 280 |
.PP |
| 281 |
\fIcmark_node *\f[] \fBcmark_iter_get_node\f[](\fIcmark_iter *iter\f[]) |
| 282 |
|
| 283 |
.PP |
| 284 |
Returns the current node. |
| 285 |
|
| 286 |
.PP |
| 287 |
\fIcmark_event_type\f[] \fBcmark_iter_get_event_type\f[](\fIcmark_iter *iter\f[]) |
| 288 |
|
| 289 |
.PP |
| 290 |
Returns the current event type. |
| 291 |
|
| 292 |
.PP |
| 293 |
\fIcmark_node *\f[] \fBcmark_iter_get_root\f[](\fIcmark_iter *iter\f[]) |
| 294 |
|
| 295 |
.PP |
| 296 |
Returns the root node. |
| 297 |
|
| 298 |
.PP |
| 299 |
\fIvoid\f[] \fBcmark_iter_reset\f[](\fIcmark_iter *iter\f[], \fIcmark_node *current\f[], \fIcmark_event_type event_type\f[]) |
| 300 |
|
| 301 |
.PP |
| 302 |
Resets the iterator so that the current node is \f[I]current\f[] and the |
| 303 |
event type is \f[I]event_type\f[]. The new current node must be a |
| 304 |
descendant of the root node or the root node itself. |
| 305 |
|
| 306 |
.SS |
| 307 |
Accessors |
| 308 |
|
| 309 |
.PP |
| 310 |
\fIvoid *\f[] \fBcmark_node_get_user_data\f[](\fIcmark_node *node\f[]) |
| 311 |
|
| 312 |
.PP |
| 313 |
Returns the user data of \f[I]node\f[]. |
| 314 |
|
| 315 |
.PP |
| 316 |
\fIint\f[] \fBcmark_node_set_user_data\f[](\fIcmark_node *node\f[], \fIvoid *user_data\f[]) |
| 317 |
|
| 318 |
.PP |
| 319 |
Sets arbitrary user data for \f[I]node\f[]. Returns 1 on success, 0 on |
| 320 |
failure. |
| 321 |
|
| 322 |
.PP |
| 323 |
\fIcmark_node_type\f[] \fBcmark_node_get_type\f[](\fIcmark_node *node\f[]) |
| 324 |
|
| 325 |
.PP |
| 326 |
Returns the type of \f[I]node\f[], or \f[C]CMARK_NODE_NONE\f[] on error. |
| 327 |
|
| 328 |
.PP |
| 329 |
\fIconst char *\f[] \fBcmark_node_get_type_string\f[](\fIcmark_node *node\f[]) |
| 330 |
|
| 331 |
.PP |
| 332 |
Like \f[I]cmark_node_get_type\f[], but returns a string representation |
| 333 |
of the type, or \f[C]"<unknown>"\f[]. |
| 334 |
|
| 335 |
.PP |
| 336 |
\fIconst char *\f[] \fBcmark_node_get_literal\f[](\fIcmark_node *node\f[]) |
| 337 |
|
| 338 |
.PP |
| 339 |
Returns the string contents of \f[I]node\f[], or an empty string if none |
| 340 |
is set. Returns NULL if called on a node that does not have string |
| 341 |
content. |
| 342 |
|
| 343 |
.PP |
| 344 |
\fIint\f[] \fBcmark_node_set_literal\f[](\fIcmark_node *node\f[], \fIconst char *content\f[]) |
| 345 |
|
| 346 |
.PP |
| 347 |
Sets the string contents of \f[I]node\f[]. Returns 1 on success, 0 on |
| 348 |
failure. |
| 349 |
|
| 350 |
.PP |
| 351 |
\fIint\f[] \fBcmark_node_get_heading_level\f[](\fIcmark_node *node\f[]) |
| 352 |
|
| 353 |
.PP |
| 354 |
Returns the heading level of \f[I]node\f[], or 0 if \f[I]node\f[] is not |
| 355 |
a heading. |
| 356 |
|
| 357 |
.PP |
| 358 |
\fIint\f[] \fBcmark_node_set_heading_level\f[](\fIcmark_node *node\f[], \fIint level\f[]) |
| 359 |
|
| 360 |
.PP |
| 361 |
Sets the heading level of \f[I]node\f[], returning 1 on success and 0 on |
| 362 |
error. |
| 363 |
|
| 364 |
.PP |
| 365 |
\fIcmark_list_type\f[] \fBcmark_node_get_list_type\f[](\fIcmark_node *node\f[]) |
| 366 |
|
| 367 |
.PP |
| 368 |
Returns the list type of \f[I]node\f[], or \f[C]CMARK_NO_LIST\f[] if |
| 369 |
\f[I]node\f[] is not a list. |
| 370 |
|
| 371 |
.PP |
| 372 |
\fIint\f[] \fBcmark_node_set_list_type\f[](\fIcmark_node *node\f[], \fIcmark_list_type type\f[]) |
| 373 |
|
| 374 |
.PP |
| 375 |
Sets the list type of \f[I]node\f[], returning 1 on success and 0 on |
| 376 |
error. |
| 377 |
|
| 378 |
.PP |
| 379 |
\fIcmark_delim_type\f[] \fBcmark_node_get_list_delim\f[](\fIcmark_node *node\f[]) |
| 380 |
|
| 381 |
.PP |
| 382 |
Returns the list delimiter type of \f[I]node\f[], or |
| 383 |
\f[C]CMARK_NO_DELIM\f[] if \f[I]node\f[] is not a list. |
| 384 |
|
| 385 |
.PP |
| 386 |
\fIint\f[] \fBcmark_node_set_list_delim\f[](\fIcmark_node *node\f[], \fIcmark_delim_type delim\f[]) |
| 387 |
|
| 388 |
.PP |
| 389 |
Sets the list delimiter type of \f[I]node\f[], returning 1 on success |
| 390 |
and 0 on error. |
| 391 |
|
| 392 |
.PP |
| 393 |
\fIint\f[] \fBcmark_node_get_list_start\f[](\fIcmark_node *node\f[]) |
| 394 |
|
| 395 |
.PP |
| 396 |
Returns starting number of \f[I]node\f[], if it is an ordered list, |
| 397 |
otherwise 0. |
| 398 |
|
| 399 |
.PP |
| 400 |
\fIint\f[] \fBcmark_node_set_list_start\f[](\fIcmark_node *node\f[], \fIint start\f[]) |
| 401 |
|
| 402 |
.PP |
| 403 |
Sets starting number of \f[I]node\f[], if it is an ordered list. |
| 404 |
Returns 1 on success, 0 on failure. |
| 405 |
|
| 406 |
.PP |
| 407 |
\fIint\f[] \fBcmark_node_get_list_tight\f[](\fIcmark_node *node\f[]) |
| 408 |
|
| 409 |
.PP |
| 410 |
Returns 1 if \f[I]node\f[] is a tight list, 0 otherwise. |
| 411 |
|
| 412 |
.PP |
| 413 |
\fIint\f[] \fBcmark_node_set_list_tight\f[](\fIcmark_node *node\f[], \fIint tight\f[]) |
| 414 |
|
| 415 |
.PP |
| 416 |
Sets the "tightness" of a list. Returns 1 on success, 0 on failure. |
| 417 |
|
| 418 |
.PP |
| 419 |
\fIconst char *\f[] \fBcmark_node_get_fence_info\f[](\fIcmark_node *node\f[]) |
| 420 |
|
| 421 |
.PP |
| 422 |
Returns the info string from a fenced code block. |
| 423 |
|
| 424 |
.PP |
| 425 |
\fIint\f[] \fBcmark_node_set_fence_info\f[](\fIcmark_node *node\f[], \fIconst char *info\f[]) |
| 426 |
|
| 427 |
.PP |
| 428 |
Sets the info string in a fenced code block, returning 1 on success |
| 429 |
and 0 on failure. |
| 430 |
|
| 431 |
.PP |
| 432 |
\fIconst char *\f[] \fBcmark_node_get_url\f[](\fIcmark_node *node\f[]) |
| 433 |
|
| 434 |
.PP |
| 435 |
Returns the URL of a link or image \f[I]node\f[], or an empty string if |
| 436 |
no URL is set. Returns NULL if called on a node that is not a link or |
| 437 |
image. |
| 438 |
|
| 439 |
.PP |
| 440 |
\fIint\f[] \fBcmark_node_set_url\f[](\fIcmark_node *node\f[], \fIconst char *url\f[]) |
| 441 |
|
| 442 |
.PP |
| 443 |
Sets the URL of a link or image \f[I]node\f[]. Returns 1 on success, 0 |
| 444 |
on failure. |
| 445 |
|
| 446 |
.PP |
| 447 |
\fIconst char *\f[] \fBcmark_node_get_title\f[](\fIcmark_node *node\f[]) |
| 448 |
|
| 449 |
.PP |
| 450 |
Returns the title of a link or image \f[I]node\f[], or an empty string |
| 451 |
if no title is set. Returns NULL if called on a node that is not a link |
| 452 |
or image. |
| 453 |
|
| 454 |
.PP |
| 455 |
\fIint\f[] \fBcmark_node_set_title\f[](\fIcmark_node *node\f[], \fIconst char *title\f[]) |
| 456 |
|
| 457 |
.PP |
| 458 |
Sets the title of a link or image \f[I]node\f[]. Returns 1 on success, 0 |
| 459 |
on failure. |
| 460 |
|
| 461 |
.PP |
| 462 |
\fIconst char *\f[] \fBcmark_node_get_on_enter\f[](\fIcmark_node *node\f[]) |
| 463 |
|
| 464 |
.PP |
| 465 |
Returns the literal "on enter" text for a custom \f[I]node\f[], or an |
| 466 |
empty string if no on_enter is set. Returns NULL if called on a |
| 467 |
non\-custom node. |
| 468 |
|
| 469 |
.PP |
| 470 |
\fIint\f[] \fBcmark_node_set_on_enter\f[](\fIcmark_node *node\f[], \fIconst char *on_enter\f[]) |
| 471 |
|
| 472 |
.PP |
| 473 |
Sets the literal text to render "on enter" for a custom \f[I]node\f[]. |
| 474 |
Any children of the node will be rendered after this text. Returns 1 on |
| 475 |
success 0 on failure. |
| 476 |
|
| 477 |
.PP |
| 478 |
\fIconst char *\f[] \fBcmark_node_get_on_exit\f[](\fIcmark_node *node\f[]) |
| 479 |
|
| 480 |
.PP |
| 481 |
Returns the literal "on exit" text for a custom \f[I]node\f[], or an |
| 482 |
empty string if no on_exit is set. Returns NULL if called on a |
| 483 |
non\-custom node. |
| 484 |
|
| 485 |
.PP |
| 486 |
\fIint\f[] \fBcmark_node_set_on_exit\f[](\fIcmark_node *node\f[], \fIconst char *on_exit\f[]) |
| 487 |
|
| 488 |
.PP |
| 489 |
Sets the literal text to render "on exit" for a custom \f[I]node\f[]. |
| 490 |
Any children of the node will be rendered before this text. Returns 1 on |
| 491 |
success 0 on failure. |
| 492 |
|
| 493 |
.PP |
| 494 |
\fIint\f[] \fBcmark_node_get_start_line\f[](\fIcmark_node *node\f[]) |
| 495 |
|
| 496 |
.PP |
| 497 |
Returns the line on which \f[I]node\f[] begins. |
| 498 |
|
| 499 |
.PP |
| 500 |
\fIint\f[] \fBcmark_node_get_start_column\f[](\fIcmark_node *node\f[]) |
| 501 |
|
| 502 |
.PP |
| 503 |
Returns the column at which \f[I]node\f[] begins. |
| 504 |
|
| 505 |
.PP |
| 506 |
\fIint\f[] \fBcmark_node_get_end_line\f[](\fIcmark_node *node\f[]) |
| 507 |
|
| 508 |
.PP |
| 509 |
Returns the line on which \f[I]node\f[] ends. |
| 510 |
|
| 511 |
.PP |
| 512 |
\fIint\f[] \fBcmark_node_get_end_column\f[](\fIcmark_node *node\f[]) |
| 513 |
|
| 514 |
.PP |
| 515 |
Returns the column at which \f[I]node\f[] ends. |
| 516 |
|
| 517 |
.SS |
| 518 |
Tree Manipulation |
| 519 |
|
| 520 |
.PP |
| 521 |
\fIvoid\f[] \fBcmark_node_unlink\f[](\fIcmark_node *node\f[]) |
| 522 |
|
| 523 |
.PP |
| 524 |
Unlinks a \f[I]node\f[], removing it from the tree, but not freeing its |
| 525 |
memory. (Use \f[I]cmark_node_free\f[] for that.) |
| 526 |
|
| 527 |
.PP |
| 528 |
\fIint\f[] \fBcmark_node_insert_before\f[](\fIcmark_node *node\f[], \fIcmark_node *sibling\f[]) |
| 529 |
|
| 530 |
.PP |
| 531 |
Inserts \f[I]sibling\f[] before \f[I]node\f[]. Returns 1 on success, 0 |
| 532 |
on failure. |
| 533 |
|
| 534 |
.PP |
| 535 |
\fIint\f[] \fBcmark_node_insert_after\f[](\fIcmark_node *node\f[], \fIcmark_node *sibling\f[]) |
| 536 |
|
| 537 |
.PP |
| 538 |
Inserts \f[I]sibling\f[] after \f[I]node\f[]. Returns 1 on success, 0 on |
| 539 |
failure. |
| 540 |
|
| 541 |
.PP |
| 542 |
\fIint\f[] \fBcmark_node_replace\f[](\fIcmark_node *oldnode\f[], \fIcmark_node *newnode\f[]) |
| 543 |
|
| 544 |
.PP |
| 545 |
Replaces \f[I]oldnode\f[] with \f[I]newnode\f[] and unlinks |
| 546 |
\f[I]oldnode\f[] (but does not free its memory). Returns 1 on success, 0 |
| 547 |
on failure. |
| 548 |
|
| 549 |
.PP |
| 550 |
\fIint\f[] \fBcmark_node_prepend_child\f[](\fIcmark_node *node\f[], \fIcmark_node *child\f[]) |
| 551 |
|
| 552 |
.PP |
| 553 |
Adds \f[I]child\f[] to the beginning of the children of \f[I]node\f[]. |
| 554 |
Returns 1 on success, 0 on failure. |
| 555 |
|
| 556 |
.PP |
| 557 |
\fIint\f[] \fBcmark_node_append_child\f[](\fIcmark_node *node\f[], \fIcmark_node *child\f[]) |
| 558 |
|
| 559 |
.PP |
| 560 |
Adds \f[I]child\f[] to the end of the children of \f[I]node\f[]. |
| 561 |
Returns 1 on success, 0 on failure. |
| 562 |
|
| 563 |
.PP |
| 564 |
\fIvoid\f[] \fBcmark_consolidate_text_nodes\f[](\fIcmark_node *root\f[]) |
| 565 |
|
| 566 |
.PP |
| 567 |
Consolidates adjacent text nodes. |
| 568 |
|
| 569 |
.SS |
| 570 |
Parsing |
| 571 |
.PP |
| 572 |
Simple interface: |
| 573 |
.IP |
| 574 |
.nf |
| 575 |
\f[C] |
| 576 |
cmark_node *document = cmark_parse_document("Hello *world*", 13, |
| 577 |
CMARK_OPT_DEFAULT); |
| 578 |
\f[] |
| 579 |
.fi |
| 580 |
.PP |
| 581 |
Streaming interface: |
| 582 |
.IP |
| 583 |
.nf |
| 584 |
\f[C] |
| 585 |
cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT); |
| 586 |
FILE *fp = fopen("myfile.md", "rb"); |
| 587 |
while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) { |
| 588 |
cmark_parser_feed(parser, buffer, bytes); |
| 589 |
if (bytes < sizeof(buffer)) { |
| 590 |
break; |
| 591 |
} |
| 592 |
} |
| 593 |
document = cmark_parser_finish(parser); |
| 594 |
cmark_parser_free(parser); |
| 595 |
\f[] |
| 596 |
.fi |
| 597 |
|
| 598 |
.PP |
| 599 |
\fIcmark_parser *\f[] \fBcmark_parser_new\f[](\fIint options\f[]) |
| 600 |
|
| 601 |
.PP |
| 602 |
Creates a new parser object. |
| 603 |
|
| 604 |
.PP |
| 605 |
\fIcmark_parser *\f[] \fBcmark_parser_new_with_mem\f[](\fIint options\f[], \fIcmark_mem *mem\f[]) |
| 606 |
|
| 607 |
.PP |
| 608 |
Creates a new parser object with the given memory allocator |
| 609 |
|
| 610 |
.PP |
| 611 |
\fIvoid\f[] \fBcmark_parser_free\f[](\fIcmark_parser *parser\f[]) |
| 612 |
|
| 613 |
.PP |
| 614 |
Frees memory allocated for a parser object. |
| 615 |
|
| 616 |
.PP |
| 617 |
\fIvoid\f[] \fBcmark_parser_feed\f[](\fIcmark_parser *parser\f[], \fIconst char *buffer\f[], \fIsize_t len\f[]) |
| 618 |
|
| 619 |
.PP |
| 620 |
Feeds a string of length \f[I]len\f[] to \f[I]parser\f[]. |
| 621 |
|
| 622 |
.PP |
| 623 |
\fIcmark_node *\f[] \fBcmark_parser_finish\f[](\fIcmark_parser *parser\f[]) |
| 624 |
|
| 625 |
.PP |
| 626 |
Finish parsing and return a pointer to a tree of nodes. |
| 627 |
|
| 628 |
.PP |
| 629 |
\fIcmark_node *\f[] \fBcmark_parse_document\f[](\fIconst char *buffer\f[], \fIsize_t len\f[], \fIint options\f[]) |
| 630 |
|
| 631 |
.PP |
| 632 |
Parse a CommonMark document in \f[I]buffer\f[] of length \f[I]len\f[]. |
| 633 |
Returns a pointer to a tree of nodes. The memory allocated for the node |
| 634 |
tree should be released using \f[I]cmark_node_free\f[] when it is no |
| 635 |
longer needed. |
| 636 |
|
| 637 |
.PP |
| 638 |
\fIcmark_node *\f[] \fBcmark_parse_file\f[](\fIFILE *f\f[], \fIint options\f[]) |
| 639 |
|
| 640 |
.PP |
| 641 |
Parse a CommonMark document in file \f[I]f\f[], returning a pointer to a |
| 642 |
tree of nodes. The memory allocated for the node tree should be released |
| 643 |
using \f[I]cmark_node_free\f[] when it is no longer needed. |
| 644 |
|
| 645 |
.SS |
| 646 |
Rendering |
| 647 |
|
| 648 |
.PP |
| 649 |
\fIchar *\f[] \fBcmark_render_xml\f[](\fIcmark_node *root\f[], \fIint options\f[]) |
| 650 |
|
| 651 |
.PP |
| 652 |
Render a \f[I]node\f[] tree as XML. It is the caller's responsibility to |
| 653 |
free the returned buffer. |
| 654 |
|
| 655 |
.PP |
| 656 |
\fIchar *\f[] \fBcmark_render_html\f[](\fIcmark_node *root\f[], \fIint options\f[]) |
| 657 |
|
| 658 |
.PP |
| 659 |
Render a \f[I]node\f[] tree as an HTML fragment. It is up to the user to |
| 660 |
add an appropriate header and footer. It is the caller's responsibility |
| 661 |
to free the returned buffer. |
| 662 |
|
| 663 |
.PP |
| 664 |
\fIchar *\f[] \fBcmark_render_man\f[](\fIcmark_node *root\f[], \fIint options\f[], \fIint width\f[]) |
| 665 |
|
| 666 |
.PP |
| 667 |
Render a \f[I]node\f[] tree as a groff man page, without the header. It |
| 668 |
is the caller's responsibility to free the returned buffer. |
| 669 |
|
| 670 |
.PP |
| 671 |
\fIchar *\f[] \fBcmark_render_commonmark\f[](\fIcmark_node *root\f[], \fIint options\f[], \fIint width\f[]) |
| 672 |
|
| 673 |
.PP |
| 674 |
Render a \f[I]node\f[] tree as a commonmark document. It is the caller's |
| 675 |
responsibility to free the returned buffer. |
| 676 |
|
| 677 |
.PP |
| 678 |
\fIchar *\f[] \fBcmark_render_latex\f[](\fIcmark_node *root\f[], \fIint options\f[], \fIint width\f[]) |
| 679 |
|
| 680 |
.PP |
| 681 |
Render a \f[I]node\f[] tree as a LaTeX document. It is the caller's |
| 682 |
responsibility to free the returned buffer. |
| 683 |
|
| 684 |
.SS |
| 685 |
Options |
| 686 |
|
| 687 |
.PP |
| 688 |
.nf |
| 689 |
\fC |
| 690 |
.RS 0n |
| 691 |
#define CMARK_OPT_DEFAULT 0 |
| 692 |
.RE |
| 693 |
\f[] |
| 694 |
.fi |
| 695 |
|
| 696 |
.PP |
| 697 |
Default options. |
| 698 |
|
| 699 |
.SS |
| 700 |
Options affecting rendering |
| 701 |
|
| 702 |
.PP |
| 703 |
.nf |
| 704 |
\fC |
| 705 |
.RS 0n |
| 706 |
#define CMARK_OPT_SOURCEPOS (1 << 1) |
| 707 |
.RE |
| 708 |
\f[] |
| 709 |
.fi |
| 710 |
|
| 711 |
.PP |
| 712 |
Include a \f[C]data\-sourcepos\f[] attribute on all block elements. |
| 713 |
|
| 714 |
.PP |
| 715 |
.nf |
| 716 |
\fC |
| 717 |
.RS 0n |
| 718 |
#define CMARK_OPT_HARDBREAKS (1 << 2) |
| 719 |
.RE |
| 720 |
\f[] |
| 721 |
.fi |
| 722 |
|
| 723 |
.PP |
| 724 |
Render \f[C]softbreak\f[] elements as hard line breaks. |
| 725 |
|
| 726 |
.PP |
| 727 |
.nf |
| 728 |
\fC |
| 729 |
.RS 0n |
| 730 |
#define CMARK_OPT_SAFE (1 << 3) |
| 731 |
.RE |
| 732 |
\f[] |
| 733 |
.fi |
| 734 |
|
| 735 |
.PP |
| 736 |
\f[C]CMARK_OPT_SAFE\f[] is defined here for API compatibility, but it no |
| 737 |
longer has any effect. "Safe" mode is now the default: set |
| 738 |
\f[C]CMARK_OPT_UNSAFE\f[] to disable it. |
| 739 |
|
| 740 |
.PP |
| 741 |
.nf |
| 742 |
\fC |
| 743 |
.RS 0n |
| 744 |
#define CMARK_OPT_UNSAFE (1 << 17) |
| 745 |
.RE |
| 746 |
\f[] |
| 747 |
.fi |
| 748 |
|
| 749 |
.PP |
| 750 |
Render raw HTML and unsafe links (\f[C]javascript:\f[], |
| 751 |
\f[C]vbscript:\f[], \f[C]file:\f[], and \f[C]data:\f[], except for |
| 752 |
\f[C]image/png\f[], \f[C]image/gif\f[], \f[C]image/jpeg\f[], or |
| 753 |
\f[C]image/webp\f[] mime types). By default, raw HTML is replaced by a |
| 754 |
placeholder HTML comment. Unsafe links are replaced by empty strings. |
| 755 |
|
| 756 |
.PP |
| 757 |
.nf |
| 758 |
\fC |
| 759 |
.RS 0n |
| 760 |
#define CMARK_OPT_NOBREAKS (1 << 4) |
| 761 |
.RE |
| 762 |
\f[] |
| 763 |
.fi |
| 764 |
|
| 765 |
.PP |
| 766 |
Render \f[C]softbreak\f[] elements as spaces. |
| 767 |
|
| 768 |
.SS |
| 769 |
Options affecting parsing |
| 770 |
|
| 771 |
.PP |
| 772 |
.nf |
| 773 |
\fC |
| 774 |
.RS 0n |
| 775 |
#define CMARK_OPT_NORMALIZE (1 << 8) |
| 776 |
.RE |
| 777 |
\f[] |
| 778 |
.fi |
| 779 |
|
| 780 |
.PP |
| 781 |
Legacy option (no effect). |
| 782 |
|
| 783 |
.PP |
| 784 |
.nf |
| 785 |
\fC |
| 786 |
.RS 0n |
| 787 |
#define CMARK_OPT_VALIDATE_UTF8 (1 << 9) |
| 788 |
.RE |
| 789 |
\f[] |
| 790 |
.fi |
| 791 |
|
| 792 |
.PP |
| 793 |
Validate UTF\-8 in the input before parsing, replacing illegal sequences |
| 794 |
with the replacement character U+FFFD. |
| 795 |
|
| 796 |
.PP |
| 797 |
.nf |
| 798 |
\fC |
| 799 |
.RS 0n |
| 800 |
#define CMARK_OPT_SMART (1 << 10) |
| 801 |
.RE |
| 802 |
\f[] |
| 803 |
.fi |
| 804 |
|
| 805 |
.PP |
| 806 |
Convert straight quotes to curly, \-\-\- to em dashes, \-\- to en |
| 807 |
dashes. |
| 808 |
|
| 809 |
.SS |
| 810 |
Version information |
| 811 |
|
| 812 |
.PP |
| 813 |
\fIint\f[] \fBcmark_version\f[](\fIvoid\f[]) |
| 814 |
|
| 815 |
.PP |
| 816 |
The library version as integer for runtime checks. Also available as |
| 817 |
macro CMARK_VERSION for compile time checks. |
| 818 |
.IP \[bu] 2 |
| 819 |
Bits 16\-23 contain the major version. |
| 820 |
.IP \[bu] 2 |
| 821 |
Bits 8\-15 contain the minor version. |
| 822 |
.IP \[bu] 2 |
| 823 |
Bits 0\-7 contain the patchlevel. |
| 824 |
.PP |
| 825 |
In hexadecimal format, the number 0x010203 represents version 1.2.3. |
| 826 |
|
| 827 |
.PP |
| 828 |
\fIconst char *\f[] \fBcmark_version_string\f[](\fIvoid\f[]) |
| 829 |
|
| 830 |
.PP |
| 831 |
The library version string for runtime checks. Also available as macro |
| 832 |
CMARK_VERSION_STRING for compile time checks. |
| 833 |
|
| 834 |
.SH |
| 835 |
AUTHORS |
| 836 |
.PP |
| 837 |
John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer. |
| 838 |
|