aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmark.h52
-rw-r--r--src/node.c185
2 files changed, 232 insertions, 5 deletions
diff --git a/src/cmark.h b/src/cmark.h
index 522e77e..a74fe93 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -44,6 +44,7 @@ typedef enum {
} cmark_node_type;
typedef enum {
+ CMARK_NO_LIST,
CMARK_BULLET_LIST,
CMARK_ORDERED_LIST
} cmark_list_type;
@@ -90,10 +91,40 @@ CMARK_EXPORT cmark_node_type
cmark_node_get_type(cmark_node *node);
CMARK_EXPORT const char*
-cmark_node_get_content(cmark_node *node);
+cmark_node_get_string_content(cmark_node *node);
CMARK_EXPORT int
-cmark_node_set_content(cmark_node *node, const char *content);
+cmark_node_set_string_content(cmark_node *node, const char *content);
+
+CMARK_EXPORT int
+cmark_node_get_header_level(cmark_node *node);
+
+CMARK_EXPORT int
+cmark_node_set_header_level(cmark_node *node, int level);
+
+CMARK_EXPORT cmark_list_type
+cmark_node_get_list_type(cmark_node *node);
+
+CMARK_EXPORT int
+cmark_node_set_list_type(cmark_node *node, cmark_list_type type);
+
+CMARK_EXPORT int
+cmark_node_get_list_start(cmark_node *node);
+
+CMARK_EXPORT int
+cmark_node_set_list_start(cmark_node *node, int start);
+
+CMARK_EXPORT int
+cmark_node_get_list_tight(cmark_node *node);
+
+CMARK_EXPORT int
+cmark_node_set_list_tight(cmark_node *node, int tight);
+
+CMARK_EXPORT const char*
+cmark_node_get_fence_info(cmark_node *node);
+
+CMARK_EXPORT int
+cmark_node_set_fence_info(cmark_node *node, const char *info);
CMARK_EXPORT const char*
cmark_node_get_url(cmark_node *node);
@@ -101,6 +132,21 @@ 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);
+
+CMARK_EXPORT int
+cmark_node_get_start_line(cmark_node *node);
+
+CMARK_EXPORT int
+cmark_node_get_start_column(cmark_node *node);
+
+CMARK_EXPORT int
+cmark_node_get_end_line(cmark_node *node);
+
// Tree manipulation
CMARK_EXPORT void
@@ -110,7 +156,7 @@ 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);
+cmark_node_insert_after(cmark_node *node, cmark_node *sibling);
CMARK_EXPORT int
cmark_node_prepend_child(cmark_node *node, cmark_node *child);
diff --git a/src/node.c b/src/node.c
index c5ce642..624baad 100644
--- a/src/node.c
+++ b/src/node.c
@@ -96,12 +96,18 @@ S_strdup(const char *str) {
}
const char*
-cmark_node_get_content(cmark_node *node) {
+cmark_node_get_string_content(cmark_node *node) {
switch (node->type) {
+ case NODE_INDENTED_CODE:
+ case NODE_FENCED_CODE:
+ case NODE_HTML:
+ return cmark_strbuf_cstr(&node->string_content);
+
case NODE_STRING:
case NODE_INLINE_HTML:
case NODE_INLINE_CODE:
return cmark_chunk_to_cstr(&node->as.literal);
+
default:
break;
}
@@ -110,13 +116,53 @@ cmark_node_get_content(cmark_node *node) {
}
int
-cmark_node_set_content(cmark_node *node, const char *content) {
+cmark_node_set_string_content(cmark_node *node, const char *content) {
switch (node->type) {
+ case NODE_INDENTED_CODE:
+ case NODE_FENCED_CODE:
+ case NODE_HTML:
+ cmark_strbuf_sets(&node->string_content, content);
+ return 1;
+
case NODE_STRING:
case NODE_INLINE_HTML:
case NODE_INLINE_CODE:
cmark_chunk_set_cstr(&node->as.literal, content);
return 1;
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int
+cmark_node_get_header_level(cmark_node *node) {
+ switch (node->type) {
+ case CMARK_NODE_ATX_HEADER:
+ case CMARK_NODE_SETEXT_HEADER:
+ return node->as.header.level;
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int
+cmark_node_set_header_level(cmark_node *node, int level) {
+ if (level < 1 || level > 6) {
+ return 0;
+ }
+
+ switch (node->type) {
+ case CMARK_NODE_ATX_HEADER:
+ case CMARK_NODE_SETEXT_HEADER:
+ node->as.header.level = level;
+ return 1;
+
default:
break;
}
@@ -124,6 +170,98 @@ cmark_node_set_content(cmark_node *node, const char *content) {
return 0;
}
+cmark_list_type
+cmark_node_get_list_type(cmark_node *node) {
+ if (node->type == CMARK_NODE_LIST) {
+ return node->as.list.list_type;
+ }
+ else {
+ return CMARK_NO_LIST;
+ }
+}
+
+int
+cmark_node_set_list_type(cmark_node *node, cmark_list_type type) {
+ if (!(type == CMARK_BULLET_LIST || type == CMARK_ORDERED_LIST)) {
+ return 0;
+ }
+
+ if (node->type == CMARK_NODE_LIST) {
+ node->as.list.list_type = type;
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
+int
+cmark_node_get_list_start(cmark_node *node) {
+ if (node->type == CMARK_NODE_LIST) {
+ return node->as.list.start;
+ }
+ else {
+ return 0;
+ }
+}
+
+int
+cmark_node_set_list_start(cmark_node *node, int start) {
+ if (start < 0) {
+ return 0;
+ }
+
+ if (node->type == CMARK_NODE_LIST) {
+ node->as.list.start = start;
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
+int
+cmark_node_get_list_tight(cmark_node *node) {
+ if (node->type == CMARK_NODE_LIST) {
+ return node->as.list.tight;
+ }
+ else {
+ return 0;
+ }
+}
+
+int
+cmark_node_set_list_tight(cmark_node *node, int tight) {
+ if (node->type == CMARK_NODE_LIST) {
+ node->as.list.tight = tight;
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
+const char*
+cmark_node_get_fence_info(cmark_node *node) {
+ if (node->type == NODE_FENCED_CODE) {
+ return cmark_strbuf_cstr(&node->as.code.info);
+ }
+ else {
+ return NULL;
+ }
+}
+
+int
+cmark_node_set_fence_info(cmark_node *node, const char *info) {
+ if (node->type == NODE_FENCED_CODE) {
+ cmark_strbuf_sets(&node->as.code.info, info);
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
const char*
cmark_node_get_url(cmark_node *node) {
switch (node->type) {
@@ -152,6 +290,49 @@ 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;
+}
+
+int
+cmark_node_get_start_line(cmark_node *node) {
+ return node->start_line;
+}
+
+int
+cmark_node_get_start_column(cmark_node *node) {
+ return node->start_column;
+}
+
+int
+cmark_node_get_end_line(cmark_node *node) {
+ return node->end_line;
+}
+
static inline bool
S_is_block(cmark_node *node) {
return node->type >= CMARK_NODE_FIRST_BLOCK