Skip to content

fix: unescape all ASCII punctuation in escapeReplacer - #565

Open
koriyoshi2041 wants to merge 1 commit into
charmbracelet:mainfrom
koriyoshi2041:fix/escape-all-ascii-punctuation
Open

fix: unescape all ASCII punctuation in escapeReplacer#565
koriyoshi2041 wants to merge 1 commit into
charmbracelet:mainfrom
koriyoshi2041:fix/escape-all-ascii-punctuation

Conversation

@koriyoshi2041

Copy link
Copy Markdown

Fixes #503.

glamour does its own backslash-unescaping in escapeReplacer (ansi/baseelement.go) instead of going through goldmark's HTML writer. That replacer was built from the markdownguide.org list and is missing several characters that CommonMark allows to be escaped, so the backslash is left in the rendered output for:

\~  \"  \$  \%  \&  \'  \,  \/  \:  \;  \=  \?  \@  \^

\~ is the one reported in #503 and is the most visible, since ~ is used for strikethrough — \~foo\~ rendered as \~foo\~ instead of ~foo~.

Per the CommonMark spec, a backslash before any ASCII punctuation character is an escape, so escapeReplacer now lists all of them.

Added TestEscapeReplacer in ansi/renderer_test.go covering the previously-missing characters plus a couple that already worked, to guard against regressions. go test ./ansi/... passes and the existing golden tests are unchanged.

glamour strips backslash escapes itself rather than going through goldmark's
HTML writer, but escapeReplacer followed the markdownguide.org list and was
missing several CommonMark-escapable characters. Most visibly a backslash
before ~ was left as-is (issue charmbracelet#503), which matters because ~ is
strikethrough; the double-quote, dollar, percent, ampersand, apostrophe,
comma, slash, colon, semicolon, equals, question mark, at, and caret escapes
were affected too. List every ASCII punctuation character so a backslash
before any of them is stripped, per the CommonMark spec.
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.

\~ incorrectly outputting \~ as opposed to outputting ~ (no strikethrough)

1 participant