Skip to content

fix: flank strikethrough tildes like asterisk emphasis, matching GitHub - #6

Open
ahalekelly wants to merge 1 commit into
software-mansion-labs:masterfrom
ahalekelly:fix/strikethrough-flanking
Open

ahalekelly wants to merge 1 commit into
software-mansion-labs:masterfrom
ahalekelly:fix/strikethrough-flanking

Conversation

@ahalekelly

Copy link
Copy Markdown

🤖 Generated with Claude Opus 5.5

What/Why?

md4c decides whether a ~/~~ run may open or close a strikethrough by looking at only one side of the run. GitHub (cmark-gfm) and micromark/remark-gfm use *'s flanking rule, which also weighs the other side. The mismatch strikes text GitHub leaves alone, and misses intraword strikes GitHub renders:

Input GitHub md4c today this PR
~$0.48 vs ~$0.65 per run plain strikes $0.48 vs plain
files in ~/foo and ~/bar plain strikes /foo and plain
~~ not ~~ plain strikes not plain
a~~b~~c strikes b plain strikes b
x~y~z strikes y plain strikes y
这是~~你好~~一段话 strikes 你好 plain strikes 你好

Prices and ~/ paths are common in coding-agent output, which is where this showed up: T3 Code's mobile app, through Enriched Markdown, struck through ~$0.48 vs ~$0.65 while its web client, which uses remark-gfm, didn't.

This replaces the tilde branch's one-sided checks with the left/right comparison the * branch uses. Run lengths, opener matching, and the subscript path are unchanged. The bug comes from upstream (mity#436). mity#440 refactors these rules and currently makes strikethrough underscore-like; I've suggested asterisk-like there, which is what this PR does. If upstream lands underscore-like, it would differ from this PR only on intraword runs.

Testing

  • Added spec examples for both directions: ~$0.48 vs ~$0.65, ~~ not ~~, and a~~b~~c 这是~~你好~~一段话. All three fail before this change; the full suite passes after it (1027 tests).
  • Compared md2html --fstrikethrough against GitHub's /markdown API (GFM mode) on 12 tilde inputs: all match.

A tilde run's opener and closer checks each looked at only one side of
the run, so `~$0.48 vs ~$0.65` and `~/foo and ~/bar` struck through and
intraword `a~~b~~c` did not. GitHub (cmark-gfm) and micromark flank `~`
like `*`; use the same left/right level comparison as the `*` branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant