Skip to content

tsx: JSX text content gets code token classes (keywords, numbers, types) #7

Description

@mehdibha

Version: @tanstack/highlight 0.0.9

Prose inside JSX text nodes is tokenized as if it were code: English words that collide with keywords get keyword, digits get number, and Capitalized words get type.

Repro

import { createHighlighter } from '@tanstack/highlight/core'
import { tsx } from '@tanstack/highlight/languages/tsx'

const h = createHighlighter({ languages: [tsx] })
console.log(h.tokenize('<Trigger>How do I get started?</Trigger>', { lang: 'tsx' }).tokens)
console.log(h.tokenize('<Item>Option 1</Item>', { lang: 'tsx' }).tokens)

Actual:

["<", ["Trigger","tag"], ">", ["How","type"], " ", ["do","keyword"], " ", ["I","type"], " ", ["get","keyword"], " started?</", ["Trigger","tag"], ">"]
["<", ["Item","tag"], ">", ["Option","type"], " ", ["1","number"], "</", ["Item","tag"], ">"]

So a sentence like "How do I get started?" renders with do and get in keyword red and How/I in the type color, and "Option 1" gets a colored digit.

Expected: text between > and the next < is inert prose with no token classes (this is also how TextMate-grammar highlighters treat JSX text).

I realize the Capitalized-identifier→type heuristic is a deliberate trade-off elsewhere, but inside a JSX text node there's no ambiguity to trade against — filing since FAQ/accuracy docs suggest corpus-driven reports are welcome. Found while migrating dotui.org's docs from shiki, character-diffing both engines over ~733k chars of tsx; button/FAQ/label copy hits this constantly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions