summaryrefslogtreecommitdiff
path: root/src/blocks.c
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-07-08 17:42:22 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-07-10 14:24:22 -0700
commit17e6720dd9b5d25aeb906bb23915a6ee13a07e3d (patch)
tree368489317ca19a0136bba3381be4ab219b1eaf21 /src/blocks.c
parent039098095da3a31dd338f2a1137e673d914489ea (diff)
Updates for new HTML block spec.
* 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.
Diffstat (limited to 'src/blocks.c')
-rw-r--r--src/blocks.c69
1 files changed, 64 insertions, 5 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 43375a4..61672ae 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -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) {
@@ -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 &&
@@ -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