diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-18 18:27:18 +0100 |
---|---|---|
committer | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-18 18:43:04 +0100 |
commit | 3f9fec6998fccabe5d61bfe84b9d2431f9d5ae53 (patch) | |
tree | 7a81e02d98354252f1c0c009031ba3e918bf3811 /src/cmark.h | |
parent | 41a73d5285368d19ac1ef17a7992bf13a352817c (diff) |
Add node constructor and accessors to the public API
The approach I'm taking is to copy inline literals internally to
NULL-terminated C strings if requested by an accessor. This allows to
return a 'const char *' that doesn't have to be freed by the caller.
Diffstat (limited to 'src/cmark.h')
-rw-r--r-- | src/cmark.h | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/cmark.h b/src/cmark.h index c5ddd5b..522e77e 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -56,8 +56,16 @@ typedef enum { typedef struct cmark_node cmark_node; typedef struct cmark_doc_parser cmark_doc_parser; -CMARK_EXPORT cmark_node_type -cmark_node_get_type(cmark_node *node); +// Construction and destruction + +CMARK_EXPORT cmark_node* +cmark_node_new(cmark_node_type type); + +CMARK_EXPORT void +cmark_node_destroy(cmark_node *node); + +CMARK_EXPORT void +cmark_free_nodes(cmark_node *e); // Tree traversal @@ -76,6 +84,23 @@ cmark_node_first_child(cmark_node *node); CMARK_EXPORT cmark_node* cmark_node_last_child(cmark_node *node); +// Accessors + +CMARK_EXPORT cmark_node_type +cmark_node_get_type(cmark_node *node); + +CMARK_EXPORT const char* +cmark_node_get_content(cmark_node *node); + +CMARK_EXPORT int +cmark_node_set_content(cmark_node *node, const char *content); + +CMARK_EXPORT const char* +cmark_node_get_url(cmark_node *node); + +CMARK_EXPORT int +cmark_node_set_url(cmark_node *node, const char *url); + // Tree manipulation CMARK_EXPORT void @@ -124,9 +149,6 @@ unsigned char *cmark_render_html(cmark_node *root); CMARK_EXPORT unsigned char *cmark_markdown_to_html(unsigned char *text, int len); -CMARK_EXPORT -void cmark_free_nodes(cmark_node *e); - #ifndef CMARK_NO_SHORT_NAMES #define NODE_DOCUMENT CMARK_NODE_DOCUMENT #define NODE_BQUOTE CMARK_NODE_BQUOTE |