From 3f9fec6998fccabe5d61bfe84b9d2431f9d5ae53 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Tue, 18 Nov 2014 18:27:18 +0100 Subject: 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. --- src/cmark.h | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'src/cmark.h') 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 -- cgit v1.2.3