@@ -91,8 +91,8 @@ static CMARK_INLINE bool S_ends_on_current_line(cmark_parser *parser, cmark_node
9191 // similar to fenced code blocks.
9292 // Types 6-7 end at a blank line, so their last content line is
9393 // the previous line and they should NOT match here.
94- (S_type (b ) == CMARK_NODE_HTML_BLOCK && b -> as .html_block_type >= 1 &&
95- b -> as .html_block_type <= 5 ) ||
94+ (S_type (b ) == CMARK_NODE_HTML_BLOCK && b -> as .html_block . type >= 1 &&
95+ b -> as .html_block . type <= 5 ) ||
9696 // Single-line blocks: finalized on same line they started
9797 b -> start_line == parser -> line_number ;
9898}
@@ -1037,7 +1037,7 @@ static bool parse_code_block_prefix(cmark_parser *parser, cmark_chunk *input,
10371037static bool parse_html_block_prefix (cmark_parser * parser ,
10381038 cmark_node * container ) {
10391039 bool res = false;
1040- int html_block_type = container -> as .html_block_type ;
1040+ int html_block_type = container -> as .html_block . type ;
10411041
10421042 assert (html_block_type >= 1 && html_block_type <= 7 );
10431043 switch (html_block_type ) {
@@ -1051,7 +1051,32 @@ static bool parse_html_block_prefix(cmark_parser *parser,
10511051 break ;
10521052 case 6 :
10531053 case 7 :
1054- res = !parser -> blank ;
1054+ if (!(parser -> options & CMARK_OPT_HTML_BLOCK_BLANK_LINES )) {
1055+ res = !parser -> blank ;
1056+ } else if (parser -> blank ) {
1057+ // Tentatively retain blank lines. The next nonblank line determines
1058+ // whether the HTML block continues:
1059+ res = true;
1060+ } else if (S_last_line_blank (container )) {
1061+ // Establish the content indentation lazily so a blank line may follow
1062+ // the opening tag. A non-indented line still terminates the block:
1063+ if (container -> as .html_block .indent == 0 && parser -> indent > 0 ) {
1064+ container -> as .html_block .indent = parser -> indent ;
1065+ }
1066+
1067+ res = container -> as .html_block .indent > 0 &&
1068+ parser -> indent >= container -> as .html_block .indent ;
1069+ } else {
1070+ // Record the shallowest positive content indentation before a blank
1071+ // line. Deeper nested HTML may then continue without changing it:
1072+ if (parser -> indent > 0 &&
1073+ (container -> as .html_block .indent == 0 ||
1074+ parser -> indent < container -> as .html_block .indent )) {
1075+ container -> as .html_block .indent = parser -> indent ;
1076+ }
1077+
1078+ res = true;
1079+ }
10551080 break ;
10561081 }
10571082
@@ -1224,7 +1249,7 @@ static void open_new_blocks(cmark_parser *parser, cmark_node **container,
12241249 input , parser -> first_nonspace ))))) {
12251250 * container = add_child (parser , * container , CMARK_NODE_HTML_BLOCK ,
12261251 parser -> first_nonspace + 1 );
1227- (* container )-> as .html_block_type = matched ;
1252+ (* container )-> as .html_block . type = matched ;
12281253 // note, we don't adjust parser->offset because the tag is part of the
12291254 // text
12301255 } else if (!indented && cont_type == CMARK_NODE_PARAGRAPH &&
@@ -1421,7 +1446,7 @@ static void add_text_to_container(cmark_parser *parser, cmark_node *container,
14211446 add_line (container , input , parser );
14221447
14231448 int matches_end_condition ;
1424- switch (container -> as .html_block_type ) {
1449+ switch (container -> as .html_block . type ) {
14251450 case 1 :
14261451 // </script>, </style>, </pre>
14271452 matches_end_condition =
0 commit comments