Skip to content

Unescape fenced code info strings before trimming whitespace - #310

Open
cpruijsen wants to merge 1 commit into
commonmark:masterfrom
cpruijsen:fix/issue-255
Open

cpruijsen wants to merge 1 commit into
commonmark:masterfrom
cpruijsen:fix/issue-255

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

Summary

Fenced code info strings are unescaped before they are trimmed, so a leading 	 or   is treated as whitespace and the first word is still used as the language class (language-js).

Adds the nine examples from #255 to test/regression.txt.

Unescape, then String.prototype.trim() (the trim already used on this line). Alternative: ASCII-only trim after unescape (as in parseInlines), or skip empty first words in the HTML renderer.

The first two cases are the ones @jgm called buggy, and cmark is the cited correct behaviour: decode character references, then trim. Keeping .trim() matches this call site instead of introducing a new whitespace rule. Can switch to the ASCII-only trim from parseInlines if you want only spaces and tabs removed after decode.

Test plan

  • npm test (744 passed, including new #255 example)
  • npm run lint
  • Confirm cmark still agrees on ```	js / ``` js

Character references such as 	 and   were trimmed as literal
text, so a leading encoded tab or space left an empty first info word
and dropped the language class. Decode first (matching cmark), then
trim.

Fixes commonmark#255
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