FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

JSX/TSX: treat non-ASCII characters in JSX text as text by ekanshul · Pull Request #3277 · pygments/pygments · GitHub

JSX/TSX: treat non-ASCII characters in JSX text as text - #3277

Open
ekanshul wants to merge 1 commit into
pygments:masterfrom
ekanshul:fix-jsx-non-ascii-text
Open

JSX/TSX: treat non-ASCII characters in JSX text as text#3277
ekanshul wants to merge 1 commit into
pygments:masterfrom
ekanshul:fix-jsx-non-ascii-text

Conversation

Copy link
Copy Markdown

JSX element content is lexed with the plain JavaScript rules, which have no rule for characters outside ASCII that are not identifier letters. So arrows, dashes, curly quotes, bullets and emoji in text content, e.g.

<li>⭐ GitHub star → Slack — it’s “great”</li>

each produce an Error token. In a real Next.js codebase these were 70 of the 336 Error tokens across its .tsx files (the rest are the type-argument issue addressed in #3272).

The JSX/TSX lexers already append a fallback rule after the inherited JavaScript rules for the apostrophe in text (<div>I'm here</div>); this adds a sibling fallback for runs of non-ASCII characters, emitted as Text. Because it comes after inherit, identifiers containing non-ASCII letters (const café = 1) are still matched by the JavaScript identifier rule first. Independent of #3272.

JSX text content is lexed with the JavaScript rules, which have no
rule for symbols outside ASCII, so arrows, dashes, curly quotes and
emoji in element content (<li>Star -> Slack</li>) produced Error
tokens. Add a fallback after the inherited rules, next to the existing
apostrophe fallback, so identifiers with non-ASCII letters keep being
lexed by the JavaScript identifier rule first.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL