Skip to content

fix(ansi): render HTML entities verbatim in code spans - #569

Open
troclaux wants to merge 1 commit into
charmbracelet:mainfrom
troclaux:fix/code-span-html-entities
Open

fix(ansi): render HTML entities verbatim in code spans#569
troclaux wants to merge 1 commit into
charmbracelet:mainfrom
troclaux:fix/code-span-html-entities

Conversation

@troclaux

@troclaux troclaux commented Jun 3, 2026

Copy link
Copy Markdown

Problem

HTML entities inside inline code spans are decoded by html.UnescapeString before rendering. This means `>` renders as > instead of the literal string >.

Code spans should render their content verbatim — the Markdown spec is clear that code spans protect their content from HTML processing.

Root Cause

In ansi/elements.go, the KindCodeSpan case calls html.UnescapeString(s) on the raw span text:

// Before
Text: html.UnescapeString(s),

// After
Text: s,

Unlike regular prose, code span content comes from n.Text(source) which is the raw source bytes — no entity decoding should be applied.

Test

Added testdata/issues/94.md and golden file confirming that `>` now renders as > rather than >.

Fixes #94

html.UnescapeString was applied to code span content, converting
entities like > to >. Code spans should render content literally.

Fixes charmbracelet#94
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.

HTML entities in inline code spans are not rendered verbatim

1 participant