Skip to content

Commit

Permalink
Updates for new HTML block spec.
Browse files Browse the repository at this point in the history
* Rewrote spec for HTML blocks.  A few other spec examples
  also changed as a result.

* Removed old `html_block_tag` scanner.  Added new
  `html_block_start` and `html_block_start_7`, as well
  as `html_block_end_n` for n = 1-5.

* Rewrote block parser for new HTML block spec.
  • Loading branch information
jgm committed Jul 9, 2015
1 parent 2c2ba6b commit e3be10f
Show file tree
Hide file tree
Showing 6 changed files with 5,886 additions and 3,264 deletions.
69 changes: 64 additions & 5 deletions src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,23 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, bufsize_t byte

} else if (container->type == NODE_HTML) {

if (parser->blank) {
all_matched = false;
switch (container->as.html_block_type) {
case 1:
case 2:
case 3:
case 4:
case 5:
// these types of blocks can accept blanks
break;
case 6:
case 7:
if (parser->blank) {
all_matched = false;
}
break;
default:
log_err("Unknown HTML block type %d", container->as.html_block_type);
exit(1);
}

} else if (container->type == NODE_PARAGRAPH) {
Expand Down Expand Up @@ -789,9 +804,13 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, bufsize_t byte
container->as.code.info = cmark_chunk_literal("");
S_advance_offset(parser, &input, parser->first_nonspace + matched - parser->offset, false);

} else if (!indented && (matched = scan_html_block_tag(&input, parser->first_nonspace))) {
} else if (!indented &&
((matched = scan_html_block_start(&input, parser->first_nonspace)) ||
(container->type != NODE_PARAGRAPH &&
(matched = scan_html_block_start_7(&input, parser->first_nonspace))))) {

container = add_child(parser, container, NODE_HTML, parser->first_nonspace + 1);
container->as.html_block_type = matched;
// note, we don't adjust parser->offset because the tag is part of the text

} else if (!indented &&
Expand Down Expand Up @@ -923,11 +942,51 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, bufsize_t byte
assert(parser->current != NULL);
}

if (container->type == NODE_CODE_BLOCK ||
container->type == NODE_HTML) {
if (container->type == NODE_CODE_BLOCK) {

add_line(container, &input, parser->offset);

} else if (container->type == NODE_HTML) {

add_line(container, &input, parser->offset);

int matches_end_condition;
switch (container->as.html_block_type) {
case 1:
// </script>, </style>, </pre>
matches_end_condition =
scan_html_block_end_1(&input, parser->first_nonspace);
break;
case 2:
// -->
matches_end_condition =
scan_html_block_end_2(&input, parser->first_nonspace);
break;
case 3:
// ?>
matches_end_condition =
scan_html_block_end_3(&input, parser->first_nonspace);
break;
case 4:
// >
matches_end_condition =
scan_html_block_end_4(&input, parser->first_nonspace);
break;
case 5:
// ]]>
matches_end_condition =
scan_html_block_end_5(&input, parser->first_nonspace);
break;
default:
matches_end_condition = 0;
break;
}

if (matches_end_condition) {
container = finalize(parser, container);
assert(parser->current != NULL);
}

} else if (parser->blank) {

// ??? do nothing
Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct cmark_node {
cmark_code code;
cmark_header header;
cmark_link link;
int html_block_type;
} as;
};

Expand Down

0 comments on commit e3be10f

Please sign in to comment.