cmark

My personal build of CMark ✏️

Commit
9fe3b46ddb58ebcd2a94e59e5687fd439d0ead32
Parent
59fd5633da5395cbd3627af4a2ab855dc43ce1e0
Author
Nick Wellnhofer <wellnhofer@aevum.de>
Date

Store link labels as children in tree structure

Diffstat

6 files changed, 7 insertions, 34 deletions

Status File Name N° Changes Insertions Deletions
Modified src/cmark.h 3 0 3
Modified src/html/html.c 9 2 7
Modified src/inlines.c 4 2 2
Modified src/node.c 18 0 18
Modified src/node.h 1 0 1
Modified src/print.c 6 3 3
diff --git a/src/cmark.h b/src/cmark.h
@@ -41,9 +41,6 @@ typedef enum {
 
     CMARK_NODE_FIRST_INLINE = CMARK_NODE_STRING,
     CMARK_NODE_LAST_INLINE  = CMARK_NODE_IMAGE,
-
-    // Other
-    CMARK_NODE_LINK_LABEL
 } cmark_node_type;
 
 typedef enum {
diff --git a/src/html/html.c b/src/html/html.c
@@ -127,11 +127,6 @@ static void inlines_to_plain_html(strbuf *html, cmark_node* ils)
 
 		case NODE_LINK:
 		case NODE_IMAGE:
-			children = ils->as.link.label;
-			visit_children = true;
-			rstack = push_inline(rstack, ils->next, "");
-			break;
-
 		case NODE_STRONG:
 		case NODE_EMPH:
 			children = ils->first_child;
@@ -201,7 +196,7 @@ static void inlines_to_html(strbuf *html, cmark_node* ils)
 			}
 
 			strbuf_puts(html, "\">");
-			children = ils->as.link.label;
+			children = ils->first_child;
 			rstack = push_inline(rstack, ils->next, "</a>");
 			break;
 
@@ -211,7 +206,7 @@ static void inlines_to_html(strbuf *html, cmark_node* ils)
 				escape_href(html, ils->as.link.url, -1);
 
 			strbuf_puts(html, "\" alt=\"");
-			inlines_to_plain_html(html, ils->as.link.label);
+			inlines_to_plain_html(html, ils->first_child);
 
 			if (ils->as.link.title) {
 				strbuf_puts(html, "\" title=\"");
diff --git a/src/inlines.c b/src/inlines.c
@@ -68,7 +68,7 @@ static inline cmark_node *make_link(cmark_node *label, unsigned char *url, unsig
 	cmark_node* e = (cmark_node *)calloc(1, sizeof(*e));
 	if(e != NULL) {
 		e->type = CMARK_NODE_LINK;
-		e->as.link.label = label;
+		e->first_child   = label;
 		e->as.link.url   = url;
 		e->as.link.title = title;
 		e->next = NULL;
@@ -735,7 +735,7 @@ match:
 	inl = opener->first_inline;
 	inl->type = is_image ? NODE_IMAGE : NODE_LINK;
 	chunk_free(&inl->as.literal);
-	inl->as.link.label = link_text;
+	inl->first_child = link_text;
 	process_emphasis(subj, opener->previous);
 	inl->as.link.url   = url;
 	inl->as.link.title = title;
diff --git a/src/node.c b/src/node.c
@@ -75,7 +75,6 @@ S_can_contain(cmark_node *node, cmark_node *child)
 	case CMARK_NODE_STRONG:
 	case CMARK_NODE_LINK:
 	case CMARK_NODE_IMAGE:
-	case CMARK_NODE_LINK_LABEL:
 		return S_is_inline(child);
 
 	default:
@@ -233,22 +232,6 @@ cmark_node_append_child(cmark_node *node, cmark_node *child)
 	return 1;
 }
 
-// Utility function used by cmark_free_nodes
-static void splice_into_list(cmark_node* e, cmark_node* children) {
-	cmark_node * tmp;
-	if (children) {
-		tmp = children;
-		// Find last child
-		while (tmp->next) {
-			tmp = tmp->next;
-		}
-		// Splice children into list
-		tmp->next = e->next;
-		e->next = children;
-	}
-	return ;
-}
-
 int
 cmark_node_check(cmark_node *node) {
 	cmark_node *cur = node;
@@ -326,7 +309,6 @@ void cmark_free_nodes(cmark_node *e)
 		case NODE_IMAGE:
 			free(e->as.link.url);
 			free(e->as.link.title);
-			splice_into_list(e, e->as.link.label);
 			break;
 		default:
 			break;
diff --git a/src/node.h b/src/node.h
@@ -31,7 +31,6 @@ typedef struct {
 } cmark_header;
 
 typedef struct {
-	struct cmark_node *label;
 	unsigned char *url;
 	unsigned char *title;
 } cmark_link;
diff --git a/src/print.c b/src/print.c
@@ -76,15 +76,15 @@ static void print_inlines(cmark_node* ils, int indent)
 				print_str(ils->as.link.title, -1);
 			}
 			putchar('\n');
-			print_inlines(ils->as.link.label, indent + 2);
+			print_inlines(ils->first_child, indent + 2);
 			break;
 		case NODE_STRONG:
 			printf("strong\n");
-			print_inlines(ils->as.link.label, indent + 2);
+			print_inlines(ils->first_child, indent + 2);
 			break;
 		case NODE_EMPH:
 			printf("emph\n");
-			print_inlines(ils->as.link.label, indent + 2);
+			print_inlines(ils->first_child, indent + 2);
 			break;
 		default:
 			break;