Emphasis closer is found inside code spans and inline parser ranges

Offen
#41 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
68/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
typescript

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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).

Vorherrschende Sprache
TypeScript
Sterne
433
Forks
12
Ø Merge
29 Min.
Gemergte PRs (30 T.)
7

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TanStack/markdown

Alle Issues in TanStack/markdown

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.