@@ -409,9 +409,11 @@ static cmark_node *finalize(cmark_parser *parser, cmark_node *b) {
409
409
// in parser. (Used to check that the counts in parser, which are updated incrementally, are
410
410
// correct.)
411
411
bool check_open_block_counts (cmark_parser * parser ) {
412
- cmark_parser tmp_parser = {0 }; // Only used for its open_block_counts field .
412
+ cmark_parser tmp_parser = {0 }; // Only used for its open_block_counts and total_open_blocks fields .
413
413
add_open_block_counts (& tmp_parser , parser -> root );
414
- return memcmp (tmp_parser .open_block_counts , parser -> open_block_counts , sizeof (parser -> open_block_counts )) == 0 ;
414
+ return
415
+ tmp_parser .total_open_blocks == parser -> total_open_blocks &&
416
+ memcmp (tmp_parser .open_block_counts , parser -> open_block_counts , sizeof (parser -> open_block_counts )) == 0 ;
415
417
}
416
418
417
419
// Add a node as child of another. Return pointer to child.
@@ -1082,10 +1084,14 @@ static cmark_node *check_open_blocks(cmark_parser *parser, cmark_chunk *input,
1082
1084
* all_matched = false;
1083
1085
cmark_node * container = parser -> root ;
1084
1086
cmark_node_type cont_type ;
1087
+ cmark_parser tmp_parser ; // Only used for its open_block_counts and total_open_blocks fields.
1088
+ memcpy (tmp_parser .open_block_counts , parser -> open_block_counts , sizeof (parser -> open_block_counts ));
1089
+ tmp_parser .total_open_blocks = parser -> total_open_blocks ;
1085
1090
1086
1091
assert (check_open_block_counts (parser ));
1087
1092
1088
1093
while (S_last_child_is_open (container )) {
1094
+ decr_open_block_count (& tmp_parser , S_type (container ));
1089
1095
container = container -> last_child ;
1090
1096
cont_type = S_type (container );
1091
1097
@@ -1097,6 +1103,26 @@ static cmark_node *check_open_blocks(cmark_parser *parser, cmark_chunk *input,
1097
1103
continue ;
1098
1104
}
1099
1105
1106
+ if (parser -> blank ) {
1107
+ const size_t n_list = read_open_block_count (& tmp_parser , CMARK_NODE_LIST );
1108
+ const size_t n_item = read_open_block_count (& tmp_parser , CMARK_NODE_ITEM );
1109
+ const size_t n_para = read_open_block_count (& tmp_parser , CMARK_NODE_PARAGRAPH );
1110
+ if (n_list + n_item + n_para == tmp_parser .total_open_blocks ) {
1111
+ if (parser -> current -> flags & CMARK_NODE__OPEN_BLOCK ) {
1112
+ if (S_type (parser -> current ) == CMARK_NODE_PARAGRAPH ) {
1113
+ container = parser -> current ;
1114
+ goto done ;
1115
+ }
1116
+ if (S_type (parser -> current ) == CMARK_NODE_ITEM ) {
1117
+ if (parser -> current -> flags & CMARK_NODE__OPEN ) {
1118
+ container = parser -> current ;
1119
+ cont_type = S_type (container );
1120
+ }
1121
+ }
1122
+ }
1123
+ }
1124
+ }
1125
+
1100
1126
switch (cont_type ) {
1101
1127
case CMARK_NODE_BLOCK_QUOTE :
1102
1128
if (!parse_block_quote_prefix (parser , input ))
@@ -1387,7 +1413,7 @@ static void add_text_to_container(cmark_parser *parser, cmark_node *container,
1387
1413
S_set_last_line_blank (container , last_line_blank );
1388
1414
1389
1415
tmp = container ;
1390
- while (tmp -> parent ) {
1416
+ while (tmp -> parent && S_last_line_blank ( tmp -> parent ) ) {
1391
1417
S_set_last_line_blank (tmp -> parent , false);
1392
1418
tmp = tmp -> parent ;
1393
1419
}
0 commit comments