cmark

My personal build of CMark ✏️

Commit
9ab35064d99ebe70e80dba88fa75f22f79751cb5
Parent
025140cf71e90cd7d54144c82ba8328493692bb6
Author
John MacFarlane <jgm@berkeley.edu>
Date

Export enums for inline, block types, list and list delim types.

Also switched from `bullet`, `ordered`, `parens`, `period` to `CMARK_BULLET_LIST`, `CMARK_ORDERED_LIST`, `CMARK_PAREN_DELIM`, `CMARK_PERIOD_DELIM`.

Diffstat

5 files changed, 50 insertions, 67 deletions

Status File Name N° Changes Insertions Deletions
Modified src/ast.h 58 0 58
Modified src/blocks.c 8 4 4
Modified src/cmark.h 41 41 0
Modified src/html/html.c 6 3 3
Modified src/print.c 4 2 2
diff --git a/src/ast.h b/src/ast.h
@@ -14,18 +14,6 @@ extern "C" {
 #define REFMAP_SIZE 16
 #define MAX_LINK_LABEL_LENGTH 1000
 
-typedef enum {
-	CMARK_INL_STRING,
-	CMARK_INL_SOFTBREAK,
-	CMARK_INL_LINEBREAK,
-	CMARK_INL_CODE,
-	CMARK_INL_RAW_HTML,
-	CMARK_INL_EMPH,
-	CMARK_INL_STRONG,
-	CMARK_INL_LINK,
-	CMARK_INL_IMAGE
-} cmark_inl_tag;
-
 struct cmark_node_inl {
 	cmark_inl_tag tag;
 	union {
@@ -56,16 +44,6 @@ struct cmark_reference_map {
 
 typedef struct cmark_reference_map cmark_reference_map;
 
-typedef enum {
-	bullet,
-	ordered
-}  cmark_list_type;
-
-typedef enum {
-	period,
-	parens
-} cmark_delim_type;
-
 // Types for blocks
 struct cmark_ListData {
 	cmark_list_type   list_type;
@@ -84,21 +62,6 @@ struct cmark_FencedCodeData {
 	cmark_strbuf      info;
 };
 
-typedef enum {
-	CMARK_BLOCK_DOCUMENT,
-	CMARK_BLOCK_BQUOTE,
-	CMARK_BLOCK_LIST,
-	CMARK_BLOCK_LIST_ITEM,
-	CMARK_BLOCK_FENCED_CODE,
-	CMARK_BLOCK_INDENTED_CODE,
-	CMARK_BLOCK_HTML,
-	CMARK_BLOCK_PARAGRAPH,
-	CMARK_BLOCK_ATX_HEADER,
-	CMARK_BLOCK_SETEXT_HEADER,
-	CMARK_BLOCK_HRULE,
-	CMARK_BLOCK_REFERENCE_DEF
-} cmark_block_tag;
-
 struct cmark_node_block {
 	cmark_block_tag tag;
 	int start_line;
@@ -202,30 +165,9 @@ static inline cmark_node_inl* cmark_make_simple(cmark_inl_tag t)
 
 #ifndef CMARK_NO_SHORT_NAMES
   #define node_inl                  cmark_node_inl
-  #define INL_STRING                CMARK_INL_STRING
-  #define INL_SOFTBREAK             CMARK_INL_SOFTBREAK
-  #define INL_LINEBREAK             CMARK_INL_LINEBREAK
-  #define INL_CODE                  CMARK_INL_CODE
-  #define INL_RAW_HTML              CMARK_INL_RAW_HTML
-  #define INL_EMPH                  CMARK_INL_EMPH
-  #define INL_STRONG                CMARK_INL_STRONG
-  #define INL_LINK                  CMARK_INL_LINK
-  #define INL_IMAGE                 CMARK_INL_IMAGE
   #define ListData                  cmark_ListData
   #define FencedCodeData            cmark_FencedCodeData
   #define node_block                cmark_node_block
-  #define BLOCK_DOCUMENT            CMARK_BLOCK_DOCUMENT
-  #define BLOCK_BQUOTE              CMARK_BLOCK_BQUOTE
-  #define BLOCK_LIST                CMARK_BLOCK_LIST
-  #define BLOCK_LIST_ITEM           CMARK_BLOCK_LIST_ITEM
-  #define BLOCK_FENCED_CODE         CMARK_BLOCK_FENCED_CODE
-  #define BLOCK_INDENTED_CODE       CMARK_BLOCK_INDENTED_CODE
-  #define BLOCK_HTML                CMARK_BLOCK_HTML
-  #define BLOCK_PARAGRAPH           CMARK_BLOCK_PARAGRAPH
-  #define BLOCK_ATX_HEADER          CMARK_BLOCK_ATX_HEADER
-  #define BLOCK_SETEXT_HEADER       CMARK_BLOCK_SETEXT_HEADER
-  #define BLOCK_HRULE               CMARK_BLOCK_HRULE
-  #define BLOCK_REFERENCE_DEF       CMARK_BLOCK_REFERENCE_DEF
   #define make_link                 cmark_make_link
   #define make_autolink             cmark_make_autolink
   #define make_str                  cmark_make_str
diff --git a/src/blocks.c b/src/blocks.c
@@ -350,10 +350,10 @@ static int parse_list_marker(chunk *input, int pos, struct ListData ** dataptr)
 			return 0;
 		} else {
 			data->marker_offset = 0; // will be adjusted later
-			data->list_type = bullet;
+			data->list_type = CMARK_BULLET_LIST;
 			data->bullet_char = c;
 			data->start = 1;
-			data->delimiter = period;
+			data->delimiter = CMARK_PERIOD_DELIM;
 			data->tight = false;
 		}
 	} else if (isdigit(c)) {
@@ -375,10 +375,10 @@ static int parse_list_marker(chunk *input, int pos, struct ListData ** dataptr)
 				return 0;
 			} else {
 				data->marker_offset = 0; // will be adjusted later
-				data->list_type = ordered;
+				data->list_type = CMARK_ORDERED_LIST;
 				data->bullet_char = 0;
 				data->start = start;
-				data->delimiter = (c == '.' ? period : parens);
+				data->delimiter = (c == '.' ? CMARK_PERIOD_DELIM : CMARK_PAREN_DELIM);
 				data->tight = false;
 			}
 		} else {
diff --git a/src/cmark.h b/src/cmark.h
@@ -10,6 +10,43 @@ extern "C" {
 
 #define CMARK_VERSION "0.1"
 
+typedef enum {
+	CMARK_INL_STRING,
+	CMARK_INL_SOFTBREAK,
+	CMARK_INL_LINEBREAK,
+	CMARK_INL_CODE,
+	CMARK_INL_RAW_HTML,
+	CMARK_INL_EMPH,
+	CMARK_INL_STRONG,
+	CMARK_INL_LINK,
+	CMARK_INL_IMAGE
+} cmark_inl_tag;
+
+typedef enum {
+	CMARK_BULLET_LIST,
+	CMARK_ORDERED_LIST
+}  cmark_list_type;
+
+typedef enum {
+	CMARK_PERIOD_DELIM,
+	CMARK_PAREN_DELIM
+} cmark_delim_type;
+
+typedef enum {
+	CMARK_BLOCK_DOCUMENT,
+	CMARK_BLOCK_BQUOTE,
+	CMARK_BLOCK_LIST,
+	CMARK_BLOCK_LIST_ITEM,
+	CMARK_BLOCK_FENCED_CODE,
+	CMARK_BLOCK_INDENTED_CODE,
+	CMARK_BLOCK_HTML,
+	CMARK_BLOCK_PARAGRAPH,
+	CMARK_BLOCK_ATX_HEADER,
+	CMARK_BLOCK_SETEXT_HEADER,
+	CMARK_BLOCK_HRULE,
+	CMARK_BLOCK_REFERENCE_DEF
+} cmark_block_tag;
+
 typedef struct cmark_node_inl cmark_node_inl;
 typedef struct cmark_node_block cmark_node_block;
 typedef struct cmark_doc_parser cmark_doc_parser;
@@ -76,6 +113,10 @@ void cmark_free_inlines(cmark_node_inl* e);
   #define BLOCK_SETEXT_HEADER       CMARK_BLOCK_SETEXT_HEADER
   #define BLOCK_HRULE               CMARK_BLOCK_HRULE
   #define BLOCK_REFERENCE_DEF       CMARK_BLOCK_REFERENCE_DEF
+  #define BULLET_LIST               CMARK_BULLET_LIST
+  #define ORDERED_LIST              CMARK_ORDERED_LIST
+  #define PERIOD_DELIM              CMARK_PERIOD_DELIM
+  #define PAREN_DELIM               CMARK_PAREN_DELIM
   #define free_simple               cmark_free_simple
   #define free_blocks               cmark_free_blocks
   #define doc_parser                cmark_doc_parser
diff --git a/src/html/html.c b/src/html/html.c
@@ -295,14 +295,14 @@ static void blocks_to_html(strbuf *html, node_block *b)
 
 			if (data->start > 1) {
 				strbuf_printf(html, "<%s start=\"%d\">\n",
-					      data->list_type == bullet ? "ul" : "ol",
+					      data->list_type == CMARK_BULLET_LIST ? "ul" : "ol",
 					      data->start);
 			} else {
-				strbuf_puts(html, data->list_type == bullet ? "<ul>\n" : "<ol>\n");
+				strbuf_puts(html, data->list_type == CMARK_BULLET_LIST ? "<ul>\n" : "<ol>\n");
 			}
 
 			rstack = push_block(rstack, b->next,
-					    data->list_type == bullet ?
+					    data->list_type == CMARK_BULLET_LIST ?
 					    "\n</ul>\n" : "\n</ol>\n", tight, false);
 			tight = data->tight;
 			visit_children = true;
diff --git a/src/print.c b/src/print.c
@@ -118,11 +118,11 @@ static void print_blocks(node_block* b, int indent)
 			break;
 		case BLOCK_LIST:
 			data = &(b->as.list);
-			if (data->list_type == ordered) {
+			if (data->list_type == CMARK_ORDERED_LIST) {
 				printf("list (type=ordered tight=%s start=%d delim=%s)\n",
 				       (data->tight ? "true" : "false"),
 				       data->start,
-				       (data->delimiter == parens ? "parens" : "period"));
+				       (data->delimiter == CMARK_PAREN_DELIM ? "parens" : "period"));
 			} else {
 				printf("list (type=bullet tight=%s bullet_char=%c)\n",
 				       (data->tight ? "true" : "false"),