Emphasis closer is found inside code spans and inline parser ranges

Aperta
#41 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start in src/inline.ts, reading parseInline and findDelimiter to understand how emphasis closers are found and how inline parsers and code spans are handled. Reproduce the three cases from the issue, then verify that links and code spans inside emphasis are parsed intact and run the relevant existing inline parser tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

When parseInline reads an emphasis opener (*, _ or ~), findDelimiter in src/inline.ts scans the raw text for the closer. The scan does not skip text that binds more tightly than emphasis, so it can find a closer inside:

  • a range that an inlineParser extension consumes, for example a link from autolinksExtension()
  • a code span

CommonMark gives code spans and autolinks a higher precedence than emphasis (spec 6.1). Without an opener before them, the same links parse correctly, because the inline parser runs first.

Reproduction

@tanstack/markdown 1.2.0:

import { parseInline } from '@tanstack/markdown'
import { autolinksExtension } from '@tanstack/markdown/extensions/autolinks'

const extensions = [autolinksExtension()]

parseInline('_see https://faceit.com/players/_Santiago_ now_', { extensions })
// emphasis: "see " + link https://faceit.com/players/_Santiago (wrong URL)
// text: " now_"

parseInline('*see https://example.com/*x*/y*', { extensions })
// emphasis: "see " + link https://example.com/
// text: "x", emphasis: "/y"

parseInline('*a `*` b*')
// emphasis: "a `", text: "` b*" (no code span)

Expected

  • _see https://faceit.com/players/_Santiago_ now_: emphasis that contains a link to https://faceit.com/players/_Santiago_
  • *see https://example.com/*x*/y*: emphasis that contains a link to https://example.com/*x*/y
  • *a `*` b*: emphasis that contains a code span with *

Possible fix

In findDelimiter, skip code spans as the main loop does. At a character that is in an inline parser's markers, call the parser and skip result.length characters when it matches. This makes the parser run twice for the same range, so the docs would need to say that parse must not have side effects.


Written by an agent (Claude Code, claude-opus-5-5).

Lingua principale
TypeScript
Stelle
433
Fork
12
Merge medio
29m
PR unite (30g)
7

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/markdown

Tutte le issue di TanStack/markdown

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.