Commit 132c29dcd04bec7383f4be36931ec4fe452506e4

Martin Mitas 2024-01-08T19:31:37

Allow indented code block to follow any block except paragraph without a blank line. Fixes #200.

diff --git a/src/md4c.c b/src/md4c.c
index b433f76..3dbf929 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -5990,11 +5990,8 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end,
 
         /* Check for indented code.
          * Note indented code block cannot interrupt a paragraph. */
-        if(line->indent >= ctx->code_indent_offset  &&
-            (pivot_line->type == MD_LINE_BLANK || pivot_line->type == MD_LINE_INDENTEDCODE))
-        {
+        if(line->indent >= ctx->code_indent_offset  &&  (pivot_line->type != MD_LINE_TEXT)) {
             line->type = MD_LINE_INDENTEDCODE;
-            MD_ASSERT(line->indent >= ctx->code_indent_offset);
             line->indent -= ctx->code_indent_offset;
             line->data = 0;
             break;
@@ -6063,7 +6060,9 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end,
         }
 
         /* Check whether we are starting code fence. */
-        if(off < ctx->size  &&  ISANYOF2(off, _T('`'), _T('~'))) {
+        if(line->indent < ctx->code_indent_offset  &&
+                off < ctx->size  &&  ISANYOF2(off, _T('`'), _T('~')))
+        {
             if(md_is_opening_code_fence(ctx, off, &off)) {
                 line->type = MD_LINE_FENCEDCODE;
                 line->data = 1;
diff --git a/test/coverage.txt b/test/coverage.txt
index de8862d..107d48d 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -339,6 +339,22 @@ bar
 ````````````````````````````````
 
 
+### [Issue 200](https://github.com/mity/md4c/issues/200)
+
+```````````````````````````````` example
+<!-- foo -->
+    ```
+    bar
+    ```
+.
+<!-- foo -->
+<pre><code>```
+bar
+```
+</code></pre>
+````````````````````````````````
+
+
 ## Code coverage
 
 ### `md_is_unicode_whitespace__()`