md_analyze_line: Fix implicit ending of HTML blocks... ... when the HTML block is not explicitly ended (before the enclosing container block ends). Fixes #149.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e34e993..ee51733 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,15 @@
# MD4C Change Log
+## Next Version (Work in Progress)
+
+Fixes:
+
+ * [#149](https://github.com/mity/md4c/issues/149):
+ A HTML block started in a container block (and not explicitly finished in
+ the block) could eat 1 line of actual contents.
+
+
## Version 0.4.7
Changes:
diff --git a/src/md4c.c b/src/md4c.c
index 19ba212..bff2fd3 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -5779,25 +5779,30 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end,
/* Check whether we are HTML block continuation. */
if(pivot_line->type == MD_LINE_HTML && ctx->html_block_type > 0) {
- int html_block_type;
+ if(n_parents < ctx->n_containers) {
+ /* HTML block is implicitly ended if the enclosing container
+ * block ends. */
+ ctx->html_block_type = 0;
+ } else {
+ int html_block_type;
- html_block_type = md_is_html_block_end_condition(ctx, off, &off);
- if(html_block_type > 0) {
- MD_ASSERT(html_block_type == ctx->html_block_type);
+ html_block_type = md_is_html_block_end_condition(ctx, off, &off);
+ if(html_block_type > 0) {
+ MD_ASSERT(html_block_type == ctx->html_block_type);
- /* Make sure this is the last line of the block. */
- ctx->html_block_type = 0;
+ /* Make sure this is the last line of the block. */
+ ctx->html_block_type = 0;
- /* Some end conditions serve as blank lines at the same time. */
- if(html_block_type == 6 || html_block_type == 7) {
- line->type = MD_LINE_BLANK;
- line->indent = 0;
- break;
+ /* Some end conditions serve as blank lines at the same time. */
+ if(html_block_type == 6 || html_block_type == 7) {
+ line->type = MD_LINE_BLANK;
+ line->indent = 0;
+ break;
+ }
}
- }
- if(n_parents == ctx->n_containers) {
line->type = MD_LINE_HTML;
+ n_parents = ctx->n_containers;
break;
}
}
diff --git a/test/coverage.txt b/test/coverage.txt
index f09721f..66d5cc8 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -306,6 +306,24 @@ foo
````````````````````````````````
+### [Issue 149](https://github.com/mity/md4c/issues/149)
+
+```````````````````````````````` example
+- <script>
+- foo
+bar
+</script>
+.
+<ul>
+<li><script>
+</li>
+<li>foo
+bar
+</script></li>
+</ul>
+````````````````````````````````
+
+
## Code coverage
### `md_is_unicode_whitespace__()`