Skip to content

tsx: apostrophe in JSX text opens a string and swallows the closing tag #5

Description

@mehdibha

Version: @tanstack/highlight 0.0.9

An apostrophe inside JSX text is treated as a string opener. Everything up to the next ' — including the element's closing tag — is consumed as one string token.

Repro

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

const h = createHighlighter({ languages: [tsx] })
console.log(h.tokenize(`<Description>We'll never share your email.</Description>`, { lang: 'tsx' }).tokens)

Actual:

["<", ["Description","tag"], ">", ["We","type"], ["'ll never share your email.</Description>", "string"]]

The 'll never share your email.</Description> run is classed string, so the prose renders string-colored and the closing </Description> tag never gets its tag class.

Expected: JSX text content is inert — We'll never share your email. stays uncolored and </Description> tokenizes as a closing tag.

Context: found while migrating dotui.org's docs from shiki, character-diffing both engines over our full corpus (~733k chars of tsx). Contractions in UI copy (We'll, can't, don't) make this common in real docs.

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