summaryrefslogtreecommitdiff
path: root/src/cmark.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmark.h')
-rw-r--r--src/cmark.h270
1 files changed, 113 insertions, 157 deletions
diff --git a/src/cmark.h b/src/cmark.h
index 4a85f26..3ad4486 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -30,49 +30,48 @@ char *cmark_markdown_to_html(const char *text, size_t len, int options);
*/
typedef enum {
- /* Error status */
- CMARK_NODE_NONE,
-
- /* Block */
- CMARK_NODE_DOCUMENT,
- CMARK_NODE_BLOCK_QUOTE,
- CMARK_NODE_LIST,
- CMARK_NODE_ITEM,
- CMARK_NODE_CODE_BLOCK,
- CMARK_NODE_HTML,
- CMARK_NODE_PARAGRAPH,
- CMARK_NODE_HEADER,
- CMARK_NODE_HRULE,
-
- CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT,
- CMARK_NODE_LAST_BLOCK = CMARK_NODE_HRULE,
-
- /* Inline */
- CMARK_NODE_TEXT,
- CMARK_NODE_SOFTBREAK,
- CMARK_NODE_LINEBREAK,
- CMARK_NODE_CODE,
- CMARK_NODE_INLINE_HTML,
- CMARK_NODE_EMPH,
- CMARK_NODE_STRONG,
- CMARK_NODE_LINK,
- CMARK_NODE_IMAGE,
-
- CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT,
- CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE,
+ /* Error status */
+ CMARK_NODE_NONE,
+
+ /* Block */
+ CMARK_NODE_DOCUMENT,
+ CMARK_NODE_BLOCK_QUOTE,
+ CMARK_NODE_LIST,
+ CMARK_NODE_ITEM,
+ CMARK_NODE_CODE_BLOCK,
+ CMARK_NODE_HTML,
+ CMARK_NODE_PARAGRAPH,
+ CMARK_NODE_HEADER,
+ CMARK_NODE_HRULE,
+
+ CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT,
+ CMARK_NODE_LAST_BLOCK = CMARK_NODE_HRULE,
+
+ /* Inline */
+ CMARK_NODE_TEXT,
+ CMARK_NODE_SOFTBREAK,
+ CMARK_NODE_LINEBREAK,
+ CMARK_NODE_CODE,
+ CMARK_NODE_INLINE_HTML,
+ CMARK_NODE_EMPH,
+ CMARK_NODE_STRONG,
+ CMARK_NODE_LINK,
+ CMARK_NODE_IMAGE,
+
+ CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT,
+ CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE,
} cmark_node_type;
-
typedef enum {
- CMARK_NO_LIST,
- CMARK_BULLET_LIST,
- CMARK_ORDERED_LIST
-} cmark_list_type;
+ CMARK_NO_LIST,
+ CMARK_BULLET_LIST,
+ CMARK_ORDERED_LIST
+} cmark_list_type;
typedef enum {
- CMARK_NO_DELIM,
- CMARK_PERIOD_DELIM,
- CMARK_PAREN_DELIM
+ CMARK_NO_DELIM,
+ CMARK_PERIOD_DELIM,
+ CMARK_PAREN_DELIM
} cmark_delim_type;
typedef struct cmark_node cmark_node;
@@ -80,10 +79,10 @@ typedef struct cmark_parser cmark_parser;
typedef struct cmark_iter cmark_iter;
typedef enum {
- CMARK_EVENT_NONE,
- CMARK_EVENT_DONE,
- CMARK_EVENT_ENTER,
- CMARK_EVENT_EXIT
+ CMARK_EVENT_NONE,
+ CMARK_EVENT_DONE,
+ CMARK_EVENT_ENTER,
+ CMARK_EVENT_EXIT
} cmark_event_type;
/**
@@ -94,13 +93,11 @@ typedef enum {
* other required properties, which it is the caller's responsibility
* to assign.
*/
-CMARK_EXPORT cmark_node*
-cmark_node_new(cmark_node_type type);
+CMARK_EXPORT cmark_node *cmark_node_new(cmark_node_type type);
/** Frees the memory allocated for a node.
*/
-CMARK_EXPORT void
-cmark_node_free(cmark_node *node);
+CMARK_EXPORT void cmark_node_free(cmark_node *node);
/**
* ## Tree Traversal
@@ -109,29 +106,24 @@ cmark_node_free(cmark_node *node);
/** Returns the next node in the sequence after 'node', or NULL if
* there is none.
*/
-CMARK_EXPORT cmark_node*
-cmark_node_next(cmark_node *node);
+CMARK_EXPORT cmark_node *cmark_node_next(cmark_node *node);
/** Returns the previous node in the sequence after 'node', or NULL if
* there is none.
*/
-CMARK_EXPORT cmark_node*
-cmark_node_previous(cmark_node *node);
+CMARK_EXPORT cmark_node *cmark_node_previous(cmark_node *node);
/** Returns the parent of 'node', or NULL if there is none.
*/
-CMARK_EXPORT cmark_node*
-cmark_node_parent(cmark_node *node);
+CMARK_EXPORT cmark_node *cmark_node_parent(cmark_node *node);
/** Returns the first child of 'node', or NULL if 'node' has no children.
*/
-CMARK_EXPORT cmark_node*
-cmark_node_first_child(cmark_node *node);
+CMARK_EXPORT cmark_node *cmark_node_first_child(cmark_node *node);
/** Returns the last child of 'node', or NULL if 'node' has no children.
*/
-CMARK_EXPORT cmark_node*
-cmark_node_last_child(cmark_node *node);
+CMARK_EXPORT cmark_node *cmark_node_last_child(cmark_node *node);
/**
* ## Iterator
@@ -182,48 +174,41 @@ cmark_node_last_child(cmark_node *node);
* type are undefined until `cmark_iter_next` is called for the first time.
*/
CMARK_EXPORT
-cmark_iter*
-cmark_iter_new(cmark_node *root);
+cmark_iter *cmark_iter_new(cmark_node *root);
/** Frees the memory allocated for an iterator.
*/
CMARK_EXPORT
-void
-cmark_iter_free(cmark_iter *iter);
+void cmark_iter_free(cmark_iter *iter);
/** Advances to the next node and returns the event type (`CMARK_EVENT_ENTER`,
* `CMARK_EVENT_EXIT` or `CMARK_EVENT_DONE`).
*/
CMARK_EXPORT
-cmark_event_type
-cmark_iter_next(cmark_iter *iter);
+cmark_event_type cmark_iter_next(cmark_iter *iter);
/** Returns the current node.
*/
CMARK_EXPORT
-cmark_node*
-cmark_iter_get_node(cmark_iter *iter);
+cmark_node *cmark_iter_get_node(cmark_iter *iter);
/** Returns the current event type.
*/
CMARK_EXPORT
-cmark_event_type
-cmark_iter_get_event_type(cmark_iter *iter);
+cmark_event_type cmark_iter_get_event_type(cmark_iter *iter);
/** Returns the root node.
*/
CMARK_EXPORT
-cmark_node*
-cmark_iter_get_root(cmark_iter *iter);
+cmark_node *cmark_iter_get_root(cmark_iter *iter);
/** Resets the iterator so that the current node is 'current' and
* the event type is 'event_type'. The new current node must be a
* descendant of the root node or the root node itself.
*/
CMARK_EXPORT
-void
-cmark_iter_reset(cmark_iter *iter, cmark_node *current,
- cmark_event_type event_type);
+void cmark_iter_reset(cmark_iter *iter, cmark_node *current,
+ cmark_event_type event_type);
/**
* ## Accessors
@@ -231,144 +216,120 @@ cmark_iter_reset(cmark_iter *iter, cmark_node *current,
/** Returns the user data of 'node'.
*/
-CMARK_EXPORT void*
-cmark_node_get_user_data(cmark_node *node);
+CMARK_EXPORT void *cmark_node_get_user_data(cmark_node *node);
/** Sets arbitrary user data for 'node'. Returns 1 on success,
* 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_set_user_data(cmark_node *node, void *user_data);
+CMARK_EXPORT int cmark_node_set_user_data(cmark_node *node, void *user_data);
/** Returns the type of 'node', or `CMARK_NODE_NONE` on error.
*/
-CMARK_EXPORT cmark_node_type
-cmark_node_get_type(cmark_node *node);
+CMARK_EXPORT cmark_node_type cmark_node_get_type(cmark_node *node);
/** Like 'cmark_node_get_type', but returns a string representation
of the type, or `"<unknown>"`.
*/
CMARK_EXPORT
-const char*
-cmark_node_get_type_string(cmark_node *node);
+const char *cmark_node_get_type_string(cmark_node *node);
/** Returns the string contents of 'node', or NULL if none.
*/
-CMARK_EXPORT const char*
-cmark_node_get_literal(cmark_node *node);
+CMARK_EXPORT const char *cmark_node_get_literal(cmark_node *node);
/** Sets the string contents of 'node'. Returns 1 on success,
* 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_set_literal(cmark_node *node, const char *content);
+CMARK_EXPORT int cmark_node_set_literal(cmark_node *node, const char *content);
/** Returns the header level of 'node', or 0 if 'node' is not a header.
*/
-CMARK_EXPORT int
-cmark_node_get_header_level(cmark_node *node);
+CMARK_EXPORT int cmark_node_get_header_level(cmark_node *node);
/** Sets the header level of 'node', returning 1 on success and 0 on error.
*/
-CMARK_EXPORT int
-cmark_node_set_header_level(cmark_node *node, int level);
+CMARK_EXPORT int cmark_node_set_header_level(cmark_node *node, int level);
/** Returns the list type of 'node', or `CMARK_NO_LIST` if 'node'
* is not a list.
*/
-CMARK_EXPORT cmark_list_type
-cmark_node_get_list_type(cmark_node *node);
+CMARK_EXPORT cmark_list_type cmark_node_get_list_type(cmark_node *node);
/** Sets the list type of 'node', returning 1 on success and 0 on error.
*/
-CMARK_EXPORT int
-cmark_node_set_list_type(cmark_node *node, cmark_list_type type);
+CMARK_EXPORT int cmark_node_set_list_type(cmark_node *node,
+ cmark_list_type type);
/** Returns the list delimiter type of 'node', or `CMARK_NO_DELIM` if 'node'
* is not a list.
*/
-CMARK_EXPORT cmark_delim_type
-cmark_node_get_list_delim(cmark_node *node);
+CMARK_EXPORT cmark_delim_type cmark_node_get_list_delim(cmark_node *node);
/** Sets the list delimiter type of 'node', returning 1 on success and 0
* on error.
*/
-CMARK_EXPORT int
-cmark_node_set_list_delim(cmark_node *node, cmark_delim_type delim);
+CMARK_EXPORT int cmark_node_set_list_delim(cmark_node *node,
+ cmark_delim_type delim);
/** Returns starting number of 'node', if it is an ordered list, otherwise 0.
*/
-CMARK_EXPORT int
-cmark_node_get_list_start(cmark_node *node);
+CMARK_EXPORT int cmark_node_get_list_start(cmark_node *node);
/** Sets starting number of 'node', if it is an ordered list. Returns 1
* on success, 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_set_list_start(cmark_node *node, int start);
+CMARK_EXPORT int cmark_node_set_list_start(cmark_node *node, int start);
/** Returns 1 if 'node' is a tight list, 0 otherwise.
*/
-CMARK_EXPORT int
-cmark_node_get_list_tight(cmark_node *node);
+CMARK_EXPORT int cmark_node_get_list_tight(cmark_node *node);
/** Sets the "tightness" of a list. Returns 1 on success, 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_set_list_tight(cmark_node *node, int tight);
+CMARK_EXPORT int cmark_node_set_list_tight(cmark_node *node, int tight);
/** Returns the info string from a fenced code block, or NULL if none.
*/
-CMARK_EXPORT const char*
-cmark_node_get_fence_info(cmark_node *node);
+CMARK_EXPORT const char *cmark_node_get_fence_info(cmark_node *node);
/** Sets the info string in a fenced code block, returning 1 on
* success and 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_set_fence_info(cmark_node *node, const char *info);
+CMARK_EXPORT int cmark_node_set_fence_info(cmark_node *node, const char *info);
/** Gets the URL of a link or image 'node', or NULL if none.
*/
-CMARK_EXPORT const char*
-cmark_node_get_url(cmark_node *node);
+CMARK_EXPORT const char *cmark_node_get_url(cmark_node *node);
/** Sets the URL of a link or image 'node'. Returns 1 on success,
* 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_set_url(cmark_node *node, const char *url);
+CMARK_EXPORT int cmark_node_set_url(cmark_node *node, const char *url);
/** Gets the title of a link or image 'node', or NULL if none.
*/
-CMARK_EXPORT const char*
-cmark_node_get_title(cmark_node *node);
+CMARK_EXPORT const char *cmark_node_get_title(cmark_node *node);
/** Sets the title of a link or image 'node'. Returns 1 on success,
* 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_set_title(cmark_node *node, const char *title);
+CMARK_EXPORT int cmark_node_set_title(cmark_node *node, const char *title);
/** Returns the line on which 'node' begins.
*/
-CMARK_EXPORT int
-cmark_node_get_start_line(cmark_node *node);
+CMARK_EXPORT int cmark_node_get_start_line(cmark_node *node);
/** Returns the column at which 'node' begins.
*/
-CMARK_EXPORT int
-cmark_node_get_start_column(cmark_node *node);
+CMARK_EXPORT int cmark_node_get_start_column(cmark_node *node);
/** Returns the line on which 'node' ends.
*/
-CMARK_EXPORT int
-cmark_node_get_end_line(cmark_node *node);
+CMARK_EXPORT int cmark_node_get_end_line(cmark_node *node);
/** Returns the column at which 'node' ends.
*/
-CMARK_EXPORT int
-cmark_node_get_end_column(cmark_node *node);
+CMARK_EXPORT int cmark_node_get_end_column(cmark_node *node);
/**
* ## Tree Manipulation
@@ -377,35 +338,30 @@ cmark_node_get_end_column(cmark_node *node);
/** Unlinks a 'node', removing it from the tree, but not freeing its
* memory. (Use 'cmark_node_free' for that.)
*/
-CMARK_EXPORT void
-cmark_node_unlink(cmark_node *node);
+CMARK_EXPORT void cmark_node_unlink(cmark_node *node);
/** Inserts 'sibling' before 'node'. Returns 1 on success, 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_insert_before(cmark_node *node, cmark_node *sibling);
+CMARK_EXPORT int cmark_node_insert_before(cmark_node *node,
+ cmark_node *sibling);
/** Inserts 'sibling' after 'node'. Returns 1 on success, 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_insert_after(cmark_node *node, cmark_node *sibling);
+CMARK_EXPORT int cmark_node_insert_after(cmark_node *node, cmark_node *sibling);
/** Adds 'child' to the beginning of the children of 'node'.
* Returns 1 on success, 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_prepend_child(cmark_node *node, cmark_node *child);
+CMARK_EXPORT int cmark_node_prepend_child(cmark_node *node, cmark_node *child);
/** Adds 'child' to the end of the children of 'node'.
* Returns 1 on success, 0 on failure.
*/
-CMARK_EXPORT int
-cmark_node_append_child(cmark_node *node, cmark_node *child);
+CMARK_EXPORT int cmark_node_append_child(cmark_node *node, cmark_node *child);
/** Consolidates adjacent text nodes.
*/
-CMARK_EXPORT void
-cmark_consolidate_text_nodes(cmark_node *root);
+CMARK_EXPORT void cmark_consolidate_text_nodes(cmark_node *root);
/**
* ## Parsing
@@ -552,28 +508,28 @@ const char *cmark_version_string();
*/
#ifndef CMARK_NO_SHORT_NAMES
-#define NODE_DOCUMENT CMARK_NODE_DOCUMENT
-#define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE
-#define NODE_LIST CMARK_NODE_LIST
-#define NODE_ITEM CMARK_NODE_ITEM
-#define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK
-#define NODE_HTML CMARK_NODE_HTML
-#define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH
-#define NODE_HEADER CMARK_NODE_HEADER
-#define NODE_HRULE CMARK_NODE_HRULE
-#define NODE_TEXT CMARK_NODE_TEXT
-#define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK
-#define NODE_LINEBREAK CMARK_NODE_LINEBREAK
-#define NODE_CODE CMARK_NODE_CODE
-#define NODE_INLINE_HTML CMARK_NODE_INLINE_HTML
-#define NODE_EMPH CMARK_NODE_EMPH
-#define NODE_STRONG CMARK_NODE_STRONG
-#define NODE_LINK CMARK_NODE_LINK
-#define NODE_IMAGE CMARK_NODE_IMAGE
-#define BULLET_LIST CMARK_BULLET_LIST
-#define ORDERED_LIST CMARK_ORDERED_LIST
-#define PERIOD_DELIM CMARK_PERIOD_DELIM
-#define PAREN_DELIM CMARK_PAREN_DELIM
+#define NODE_DOCUMENT CMARK_NODE_DOCUMENT
+#define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE
+#define NODE_LIST CMARK_NODE_LIST
+#define NODE_ITEM CMARK_NODE_ITEM
+#define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK
+#define NODE_HTML CMARK_NODE_HTML
+#define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH
+#define NODE_HEADER CMARK_NODE_HEADER
+#define NODE_HRULE CMARK_NODE_HRULE
+#define NODE_TEXT CMARK_NODE_TEXT
+#define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK
+#define NODE_LINEBREAK CMARK_NODE_LINEBREAK
+#define NODE_CODE CMARK_NODE_CODE
+#define NODE_INLINE_HTML CMARK_NODE_INLINE_HTML
+#define NODE_EMPH CMARK_NODE_EMPH
+#define NODE_STRONG CMARK_NODE_STRONG
+#define NODE_LINK CMARK_NODE_LINK
+#define NODE_IMAGE CMARK_NODE_IMAGE
+#define BULLET_LIST CMARK_BULLET_LIST
+#define ORDERED_LIST CMARK_ORDERED_LIST
+#define PERIOD_DELIM CMARK_PERIOD_DELIM
+#define PAREN_DELIM CMARK_PAREN_DELIM
#endif
#ifdef __cplusplus