Skip to content

Don't escape underscores that can't close emphasis#582

Open
apoorva-01 wants to merge 1 commit into
hukkin:masterfrom
apoorva-01:dont-escape-literal-underscores
Open

Don't escape underscores that can't close emphasis#582
apoorva-01 wants to merge 1 commit into
hukkin:masterfrom
apoorva-01:dont-escape-literal-underscores

Conversation

@apoorva-01

Copy link
Copy Markdown

Closes #557

Right now literal underscores that can't form emphasis still get escaped, so *target=_blank* turns into *target=\_blank* and As a ______, into a row of \_. Same HTML, just noisy.

Fix: emphasis needs a closer, so only escape underscore runs that can close emphasis (per §6.2). If the closers stay escaped, the openers have nothing to pair with. Intraword and isolated _ were already fine.

One catch: a _-emphasis span wraps its content in literal _ markers that can pair with a relaxed underscore in the same inline, so escaping stays conservative when an inline contains any _ emphasis (the small inline renderer handles that). I kept it to this local heuristic rather than full delimiter pairing, happy to go bigger if you'd prefer.

Heads up it changes default output for everyone (like #464/#465), and Do _escape in the fixtures now stays unescaped on purpose. Added spec-style tests, spec suite unchanged, fuzzed ~600k inputs for same-HTML, tox green.

Emphasis needs a closing delimiter, so escaping only the runs that can
close keeps every underscore literal without the needless backslashes.
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.

Don't escape literal underscores

1 participant