From 26da23fa723a05e34bd1e036aa636f4a974bea4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mit=C3=A1=C5=A1?= Date: Wed, 21 Feb 2024 08:51:05 +0100 Subject: [PATCH] Make striketrough spans follow same flanking rules... ... as other emphasis spans. Fixes #242. --- CHANGELOG.md | 5 +++++ src/md4c.c | 30 +++--------------------------- test/regressions.txt | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0114eb84..e02071b6 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 a56204ea..054c559e 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 284a5326..7411206c 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" +. +

copy ~user1/file to ~user2/file

+

copy "~user1/file" to "~user2/file"

+. +--fstrikethrough +````````````````````````````````