cmark

My personal build of CMark ✏️

Commit
ff2c9dc143b730a0fa5cfeddec0c355edba72e51
Parent
b2306ee0551cb4d319046e63aa96ee5a4062ae47
Author
John MacFarlane <jgm@berkeley.edu>
Date

Removed enumlevel field of renderer.

Now we just calculate this in the latex renderer.

Diffstat

3 files changed, 17 insertions, 9 deletions

Status File Name N° Changes Insertions Deletions
Modified src/latex.c 23 16 7
Modified src/render.c 2 1 1
Modified src/render.h 1 0 1
diff --git a/src/latex.c b/src/latex.c
@@ -243,6 +243,21 @@ get_link_type(cmark_node *node)
 }
 
 static int
+S_get_enumlevel(cmark_node *node)
+{
+	int enumlevel = 0;
+	cmark_node *tmp = node;
+	while (tmp) {
+		if (tmp->type == CMARK_NODE_LIST &&
+		    cmark_node_get_list_type(node) == CMARK_ORDERED_LIST) {
+			enumlevel++;
+		}
+		tmp = tmp->parent;
+	}
+	return enumlevel;
+}
+
+static int
 S_render_node(cmark_node *node, cmark_event_type ev_type,
               cmark_renderer *renderer)
 {
@@ -271,9 +286,6 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
 	case CMARK_NODE_LIST:
 		list_type = cmark_node_get_list_type(node);
 		if (entering) {
-			if (list_type == CMARK_ORDERED_LIST) {
-				renderer->enumlevel++;
-			}
 			LIT("\\begin{");
 			LIT(list_type == CMARK_ORDERED_LIST ?
 			    "enumerate" : "itemize");
@@ -284,16 +296,13 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
 				sprintf(list_number_string,
 				         "%d", list_number);
 				LIT("\\setcounter{enum");
-				LIT((char *)roman_numerals[renderer->enumlevel]);
+				LIT((char *)roman_numerals[S_get_enumlevel(node)]);
 				LIT("}{");
 				OUT(list_number_string, false, NORMAL);
 				LIT("}");
 				CR();
 			}
 		} else {
-			if (list_type == CMARK_ORDERED_LIST) {
-				renderer->enumlevel--;
-			}
 			LIT("\\end{");
 			LIT(list_type == CMARK_ORDERED_LIST ?
 			    "enumerate" : "itemize");
diff --git a/src/render.c b/src/render.c
@@ -141,7 +141,7 @@ cmark_render(cmark_node *root,
 	}
 
 	cmark_renderer renderer = { options, &buf, &pref, 0, width,
-				    0, 0, 0, true, false, false,
+				    0, 0, true, false, false,
 	                            outc, S_cr, S_blankline, S_out };
 
 	while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
diff --git a/src/render.h b/src/render.h
@@ -24,7 +24,6 @@ struct cmark_renderer {
 	int width;
 	int need_cr;
 	bufsize_t last_breakable;
-	int enumlevel;
 	bool begin_line;
 	bool no_wrap;
 	bool in_tight_list_item;