Commit 3848bfb6cc23000205695128a24160bf5f6cac6b

Martin Mitáš 2024-02-21T08:51:05

Make striketrough spans follow same flanking rules... ... as other emphasis spans. Fixes #242.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0114eb8..e02071b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,11 @@ Fixes:
    Fix quadratic time and output size behavior caused by malicious misuse of
    link reference definitions.
 
+ - [#242](https://github.com/mity/md4c/issues/242):
+   The strike-through extension (with flag `MD_FLAG_STRIKETHROUGH`) now follows
+   same logic as other emphasis spans in respect to punctuation character and
+   word boundaries.
+
 
 ## Version 0.5.2
 
diff --git a/src/md4c.c b/src/md4c.c
index a56204e..054c559 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -3295,35 +3295,11 @@ md_collect_marks(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines, int table_m
                 continue;
             }
 
-            /* A potential strikethrough start/end. */
-            if(ch == _T('~')) {
+            /* A potential strikethrough/equation start/end. */
+            if(ch == _T('$') || ch == _T('~')) {
                 OFF tmp = off+1;
 
-                while(tmp < line->end  &&  CH(tmp) == _T('~'))
-                    tmp++;
-
-                if(tmp - off < 3) {
-                    unsigned flags = 0;
-
-                    if(tmp < line->end  &&  !ISUNICODEWHITESPACE(tmp))
-                        flags |= MD_MARK_POTENTIAL_OPENER;
-                    if(off > line->beg  &&  !ISUNICODEWHITESPACEBEFORE(off))
-                        flags |= MD_MARK_POTENTIAL_CLOSER;
-                    if(flags != 0)
-                        ADD_MARK(ch, off, tmp, flags);
-                }
-
-                off = tmp;
-                continue;
-            }
-
-            /* A potential equation start/end */
-            if(ch == _T('$')) {
-                /* We can have at most two consecutive $ signs,
-                 * where two dollar signs signify a display equation. */
-                OFF tmp = off+1;
-
-                while(tmp < line->end && CH(tmp) == _T('$'))
+                while(tmp < line->end && CH(tmp) == ch)
                     tmp++;
 
                 if(tmp - off <= 2) {
diff --git a/test/regressions.txt b/test/regressions.txt
index 284a532..7411206 100644
--- a/test/regressions.txt
+++ b/test/regressions.txt
@@ -726,3 +726,17 @@ https://example.com/dir/
 .
 --fpermissive-url-autolinks
 ````````````````````````````````
+
+
+## [Issue 242](https://github.com/mity/md4c/issues/242)
+
+```````````````````````````````` example
+copy ~user1/file to ~user2/file
+
+copy "~user1/file" to "~user2/file"
+.
+<p>copy ~user1/file to ~user2/file</p>
+<p>copy &quot;~user1/file&quot; to &quot;~user2/file&quot;</p>
+.
+--fstrikethrough
+````````````````````````````````