Commit a8bb4d3020eb1cfa07f01241c2aa668d91011cb5

Martin Mitas 2022-01-06T16:01:55

md_is_table_underline: Remove requirement for minimal length of a cell underline. Fixes #169.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5381d55..8e54ba2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,7 +24,6 @@ Changes:
    0.30 notes](https://github.com/commonmark/commonmark-spec/releases/tag/0.30)
    for more info.
 
-
 Fixes:
 
  * [#163](https://github.com/mity/md4c/issues/163):
@@ -35,6 +34,11 @@ Fixes:
    work, it's not needed, and it can actually be confusing with URLs such as
    `http://www.example.com/~johndoe/`.
 
+ * [#169](https://github.com/mity/md4c/issues/169):
+   Table underline now does not require 3 characters per table column anymore.
+   One dash (optionally with a leading or tailing `:` appended or prepended)
+   is now sufficient. This improves compatibility with the GFM.
+
 
 ## Version 0.4.8
 
diff --git a/src/md4c.c b/src/md4c.c
index 40066b2..9192468 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -5212,19 +5212,17 @@ md_is_table_underline(MD_CTX* ctx, OFF beg, OFF* p_end, unsigned* p_col_count)
     }
 
     while(1) {
-        OFF cell_beg;
         int delimited = FALSE;
 
         /* Cell underline ("-----", ":----", "----:" or ":----:") */
-        cell_beg = off;
         if(off < ctx->size  &&  CH(off) == _T(':'))
             off++;
+        if(off < ctx->size  &&  CH(off) != _T('-'))
+            return FALSE;
         while(off < ctx->size  &&  CH(off) == _T('-'))
             off++;
         if(off < ctx->size  &&  CH(off) == _T(':'))
             off++;
-        if(off - cell_beg < 3)
-            return FALSE;
 
         col_count++;
 
diff --git a/test/tables.txt b/test/tables.txt
index bef5799..b220f66 100644
--- a/test/tables.txt
+++ b/test/tables.txt
@@ -165,27 +165,6 @@ Lorem ipsum dolor sit amet.
 </table>
 ````````````````````````````````
 
-The underline of the table is crucial for recognition of the table, count of
-its columns and their alignment: The line has to contain at least one pipe,
-and it has provide at least three dash (`-`) characters for every column in
-the table.
-
-Thus this is not a table because there are too few dashes for Column 2.
-
-```````````````````````````````` example
-| Column 1 | Column 2
-| ---------|--
-| foo      | bar
-| baz      | qux
-| quux     | quuz
-.
-<p>| Column 1 | Column 2
-| ---------|--
-| foo      | bar
-| baz      | qux
-| quux     | quuz</p>
-````````````````````````````````
-
 The first, the last or both the first and the last dash in each column
 underline can be replaced with a colon (`:`) to request left, right or middle
 alignment of the respective column: