cmark

My personal build of CMark ✏️

Commit
56b1123c6662169ffe6a0eabc67f8533e745eb97
Parent
d63dd090693f6065b7a79d634bf88e45da089b53
Author
John MacFarlane <jgm@berkeley.edu>
Date

Allow new list item container indented > 4 spaces.

This fixes cases like:

``` 1. a

2. b

3. c ```

Diffstat

1 file changed, 15 insertions, 11 deletions

Status File Name N° Changes Insertions Deletions
Modified src/blocks.c 26 15 11
diff --git a/src/blocks.c b/src/blocks.c
@@ -696,16 +696,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
 		indented = indent >= CODE_INDENT;
 		blank = is_line_end_char(peek_at(&input, first_nonspace));
 
-		if (indented && !maybe_lazy && !blank) {
-				offset += CODE_INDENT;
-				container = add_child(parser, container, NODE_CODE_BLOCK, offset + 1);
-				container->as.code.fenced = false;
-				container->as.code.fence_char = 0;
-				container->as.code.fence_length = 0;
-				container->as.code.fence_offset = 0;
-				container->as.code.info = cmark_chunk_literal("");
-
-		} else if (!indented && peek_at(&input, first_nonspace) == '>') {
+		if (!indented && peek_at(&input, first_nonspace) == '>') {
 
 			offset = first_nonspace + 1;
 			// optional following character
@@ -765,7 +756,10 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
 			container = finalize(parser, container);
 			offset = input.len - 1;
 
-		} else if ((matched = parse_list_marker(&input, first_nonspace, &data))) {
+		} else if ((matched = parse_list_marker(&input, first_nonspace, &data)) &&
+			   (!indented || container->type == NODE_LIST)) {
+			// Note that we can have new list items starting with >= 4
+			// spaces indent, as long as the list container is still open.
 
 			// compute padding:
 			offset = first_nonspace + matched;
@@ -804,6 +798,16 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
 			/* TODO: static */
 			memcpy(&container->as.list, data, sizeof(*data));
 			free(data);
+
+		} else if (indented && !maybe_lazy && !blank) {
+				offset += CODE_INDENT;
+				container = add_child(parser, container, NODE_CODE_BLOCK, offset + 1);
+				container->as.code.fenced = false;
+				container->as.code.fence_char = 0;
+				container->as.code.fence_length = 0;
+				container->as.code.fence_offset = 0;
+				container->as.code.info = cmark_chunk_literal("");
+
 		} else {
 			break;
 		}