Skip to content

fix: apply GFM flanking rules to strikethrough delimiters - #48

Open
RobinDev wants to merge 1 commit into
tempestphp:mainfrom
RobinDev:fix/strikethrough-flanking
Open

RobinDev wants to merge 1 commit into
tempestphp:mainfrom
RobinDev:fix/strikethrough-flanking

Conversation

@RobinDev

@RobinDev RobinDev commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

A tilde delimiter opens and closes strikethrough regardless of what surrounds it, so text that merely uses ~ as "approximately" gets struck:

~11km / ~750m de dénivelé
main <p><s>11km / </s>750m de dénivelé</p>
this PR <p>~11km / ~750m de dénivelé</p>

The GFM strikethrough extension uses the same flanking rules as emphasis: an opening run may not be followed by whitespace, a closing run may not be preceded by it, and the two runs must be the same length. league/commonmark leaves every case in the table below alone; main strikes four of them.

shouldParse() is unchanged. parse() now looks for a run that can actually close, and falls back to the literal text when there is none:

Markdown main this PR league/commonmark
~struck~ <s> <s> <del>
~~struck~~ <s> <s> <del>
a~struck~b <s> <s> <del>
~ struck ~ <s> literal literal
~11km / ~750m <s>11km / </s>750m literal literal
~struck~~ <s> literal literal
~~struck~ <s> literal literal

Worth fixing now because #47 widened it. Those rule sets did not run StrikethroughRule before, so a blockquote, a list item or a table cell could not hit this; they can now. On a personal dataset the count of wrongly struck documents roughly tripled when #47 landed, and drops to zero with this PR.

A run of three or more tildes no longer delimits strikethrough either, which is what league does and what the fenced-code rule from #42 already assumes.

@github-actions

Copy link
Copy Markdown

Benchmark Results

Comparison of fix/strikethrough-flanking against main (b4cd28e8892eb3049af2bc67612f34149ada5aa7).

Open to see the benchmark results

No benchmark changes above ±5%.

Generated by phpbench against commit 60cd004

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant