From fd13d0211f33a134a4c73882f1f2eaa423f1794a Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 19 Nov 2014 17:05:04 +0100 Subject: Accessors for link titles --- src/cmark.h | 6 ++++++ src/node.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/cmark.h b/src/cmark.h index d9daccd..2b42486 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -132,6 +132,12 @@ cmark_node_get_url(cmark_node *node); CMARK_EXPORT int cmark_node_set_url(cmark_node *node, const char *url); +CMARK_EXPORT const char* +cmark_node_get_title(cmark_node *node); + +CMARK_EXPORT int +cmark_node_set_title(cmark_node *node, const char *title); + // Tree manipulation CMARK_EXPORT void diff --git a/src/node.c b/src/node.c index 814e0e1..f2649e9 100644 --- a/src/node.c +++ b/src/node.c @@ -275,6 +275,34 @@ cmark_node_set_url(cmark_node *node, const char *url) { return 0; } +const char* +cmark_node_get_title(cmark_node *node) { + switch (node->type) { + case NODE_LINK: + case NODE_IMAGE: + return (char *)node->as.link.title; + default: + break; + } + + return NULL; +} + +int +cmark_node_set_title(cmark_node *node, const char *title) { + switch (node->type) { + case NODE_LINK: + case NODE_IMAGE: + free(node->as.link.title); + node->as.link.title = (unsigned char *)S_strdup(title); + return 1; + default: + break; + } + + return 0; +} + static inline bool S_is_block(cmark_node *node) { return node->type >= CMARK_NODE_FIRST_BLOCK -- cgit v1.2.3