summaryrefslogtreecommitdiff
path: root/src/cmark.c
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-16 22:35:03 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-16 22:35:03 -0800
commit09c365fb0a75c9da46a1319aed1888665d6dc627 (patch)
tree32200fe4a9827ff8b185622ef485a69b7f62b4ae /src/cmark.c
parent9ab35064d99ebe70e80dba88fa75f22f79751cb5 (diff)
Added some basic functions for traversing/editing blocks in AST.
Diffstat (limited to 'src/cmark.c')
-rw-r--r--src/cmark.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/cmark.c b/src/cmark.c
index e7f6899..768d462 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -7,6 +7,72 @@
#include "buffer.h"
#include "ast.h"
+// AST traversal and manipulation functions
+
+cmark_node_block *cmark_block_next(cmark_node_block *current)
+{
+ return current->next;
+}
+
+cmark_node_block *cmark_block_previous(cmark_node_block *current)
+{
+ return current->prev;
+}
+
+cmark_node_block *cmark_block_parent(cmark_node_block *current)
+{
+ return current->parent;
+}
+
+cmark_node_block *cmark_block_children(cmark_node_block *current)
+{
+ return current->children;
+}
+
+void cmark_block_delete(cmark_node_block *current)
+{
+ if (current->prev) {
+ current->prev->next = current->next;
+ }
+ if (current->next) {
+ current->next->prev = current->prev;
+ }
+ current->next = NULL;
+ cmark_free_blocks(current);
+}
+
+void cmark_block_insert_before(cmark_node_block *new, cmark_node_block *current)
+{
+ // Find last node in new:
+ cmark_node_block *new_last = new;
+ while (new_last->next) {
+ new_last = new_last->next;
+ }
+ new_last->next = current;
+ current->prev = new_last;
+ if (current->prev) {
+ current->prev->next = new;
+ new->prev = current->prev;
+ }
+}
+
+void cmark_block_insert_after(cmark_node_block *current, cmark_node_block *new)
+{
+ // Find last node in new:
+ cmark_node_block *new_last = new;
+ while (new_last->next) {
+ new_last = new_last->next;
+ }
+ if (current->next) {
+ new_last->next = current->next;
+ current->next->prev = new_last;
+ }
+ current->next = new;
+ new->prev = current;
+}
+
+/* * */
+
unsigned char *cmark_markdown_to_html(unsigned char *text, int len)
{
node_block *blocks;