Commit 26003b8881f25fb47a75a128ef3e6af7a05e4680

Martin Mitas 2020-12-04T20:42:22

md_is_container_mark: Recognize list item marks just before EOF. We were recognizing the list item marks when a new line or a blank character follows. However, given end-of-file means implicitly also an end-of-line, we should recognize in that situation too. Fixes #139.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3b465d4..efe693f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,9 @@ Fixes:
    The tag `<tbody></tbody>` is suppressed whenever the table has zero body
    rows.
 
+ * [#139](https://github.com/mity/md4c/issues/139):
+   Recognize a list item mark even when EOF follows it.
+
 
 ## Version 0.4.6
 
diff --git a/src/md4c.c b/src/md4c.c
index 314000e..f2af228 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -5611,11 +5611,11 @@ md_is_container_mark(MD_CTX* ctx, unsigned indent, OFF beg, OFF* p_end, MD_CONTA
     OFF off = beg;
     OFF max_end;
 
-    if(indent >= ctx->code_indent_offset)
+    if(off >= ctx->size  ||  indent >= ctx->code_indent_offset)
         return FALSE;
 
     /* Check for block quote mark. */
-    if(off < ctx->size  &&  CH(off) == _T('>')) {
+    if(CH(off) == _T('>')) {
         off++;
         p_container->ch = _T('>');
         p_container->is_loose = FALSE;
@@ -5627,13 +5627,13 @@ md_is_container_mark(MD_CTX* ctx, unsigned indent, OFF beg, OFF* p_end, MD_CONTA
     }
 
     /* Check for list item bullet mark. */
-    if(off+1 < ctx->size  &&  ISANYOF(off, _T("-+*"))  &&  (ISBLANK(off+1) || ISNEWLINE(off+1))) {
+    if(ISANYOF(off, _T("-+*"))  &&  (off+1 >= ctx->size || ISBLANK(off+1) || ISNEWLINE(off+1))) {
         p_container->ch = CH(off);
         p_container->is_loose = FALSE;
         p_container->is_task = FALSE;
         p_container->mark_indent = indent;
         p_container->contents_indent = indent + 1;
-        *p_end = off + 1;
+        *p_end = off+1;
         return TRUE;
     }
 
@@ -5646,16 +5646,16 @@ md_is_container_mark(MD_CTX* ctx, unsigned indent, OFF beg, OFF* p_end, MD_CONTA
         p_container->start = p_container->start * 10 + CH(off) - _T('0');
         off++;
     }
-    if(off > beg  &&  off+1 < ctx->size  &&
+    if(off > beg  &&
        (CH(off) == _T('.') || CH(off) == _T(')'))  &&
-       (ISBLANK(off+1) || ISNEWLINE(off+1)))
+       (off+1 >= ctx->size || ISBLANK(off+1) || ISNEWLINE(off+1)))
     {
         p_container->ch = CH(off);
         p_container->is_loose = FALSE;
         p_container->is_task = FALSE;
         p_container->mark_indent = indent;
         p_container->contents_indent = indent + off - beg + 1;
-        *p_end = off + 1;
+        *p_end = off+1;
         return TRUE;
     }