Skip to content

fix(markdown): decode inline character references - #56

Merged
Mucheen merged 2 commits into
mainfrom
codex/markdown-character-references-fork
Nov 22, 2026
Merged

Mucheen merged 2 commits into
mainfrom
codex/markdown-character-references-fork

Conversation

@Mucheen

@Mucheen Mucheen commented Nov 22, 2026 •

Copy link
Copy Markdown

Carries the Markdown fix from vivaui/viva#398 on the current fork main.

What this changes

Decode complete named, decimal, and hexadecimal character references in Markdown inline text. Keep the decoded characters in the surrounding text span so the line can measure and wrap them together. Code spans, fenced code, escaped ampersands, and malformed references keep their literal text.

Why

Language servers can use   to preserve indentation in Markdown documentation. For example, Pyrefly's hover for Python's re module includes runs of   before regular expression syntax examples. Viva rendered each reference as six visible characters, widening the popup and introducing unnecessary line breaks.

How it was verified

  • gofmt -l across tracked Go files, git diff --check, and go vet ./...
  • Confirmed the new parser test fails before the fix and passes afterward. go test -race ./markdown ./components ./ui/markdown -count=1 -timeout=75s passes on macOS ARM64.
  • go test -p=4 ./... -count=1 -timeout=3m passes on macOS ARM64 with Go 1.26.10, covering 127 packages. Go 1.27.4 raised the packaging deployment target to macOS 13.0 against 12.0 fixtures on the unchanged baseline as well.
  • Lithe's 12 existing hover tests and four headless screenshot cases pass with the patch applied to its pinned Viva revision.
  • Native window and Windows interaction checks

Visual evidence

  • Changed area is the editor's Markdown hover for the re token in import re.
  • To reproduce in Viva, pass     A|B Matches A or B. to markdown.Document.Parse and draw it with components.MarkdownView. The Lithe screenshots use the same path with a synthetic hover response.
  • Captured on macOS ARM64 using vivahead, light and dark, English and Simplified Chinese, 1100 × 670 logical pixels at 2× scale. Before, light · After, light · All eight screenshots
  • TestInlineCharacterReferences covers indentation, numeric and named references, escaped and malformed inputs, one-pass decoding, emphasis and link labels, and literal text in code.

Where the boundary sits

Decoding is owned by Viva's Markdown reader. Applications provide Markdown and consume its text spans without needing to add their own substitutions.

Cost

On Apple M5, BenchmarkParse measured a median 14.9 to 15.0 µs per operation across five samples, with 0 allocations per operation in both cases. Character reference lookahead is bounded by the longest supported name. Ordinary spans still reuse slices of the source. The standard library entity table adds 110,864 bytes to a stripped macOS ARM64 binary that only parses and prints Markdown spans.

The fork branch also passes go test ./markdown ./components ./ui/markdown -count=1 on macOS ARM64.

The advisory size job already exceeds the 3,840,000-byte ceiling for hello darwin/arm64 on fork main. The CI runs reported 4,393,330 bytes on main and 4,459,378 bytes on this branch. Baseline size job · Patch size job

Lithe tested this branch in a temporary module and adapted the argument order of 16 ui.PopoverWith calls for the newer fork API. All 12 hover tests and the four screenshot cases passed. The Lithe dependency update will use a fork main commit.

Review follow-up

Go's standard library omits ≪⃒ and ≫⃒ because their UTF-8 replacements are longer than the source. The follow-up fills those two mappings and adds a failing-then-passing regression for adjacent references. All 2,125 semicolon-terminated names and three boundary cases passed with Go 1.26.10 and 1.27.4. The twelve desktop hover tests and four headless screenshot cases also passed again on the updated fork candidate.

@Mucheen
Mucheen marked this pull request as ready for review November 22, 2026 09:05
@Mucheen
Mucheen merged commit 103c195 into main Nov 22, 2026
15 of 16 checks passed
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.

1 participant