Repository navigation
fix(markdown): decode inline character references - #56
Merged
Merged
Conversation
Mucheen
marked this pull request as ready for review
November 22, 2026 09:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'sremodule 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 -lacross tracked Go files,git diff --check, andgo vet ./...go test -race ./markdown ./components ./ui/markdown -count=1 -timeout=75spasses on macOS ARM64.go test -p=4 ./... -count=1 -timeout=3mpasses 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.Visual evidence
retoken inimport re. A|B Matches A or B.tomarkdown.Document.Parseand draw it withcomponents.MarkdownView. The Lithe screenshots use the same path with a synthetic hover response.vivahead, light and dark, English and Simplified Chinese, 1100 × 670 logical pixels at 2× scale. Before, light · After, light · All eight screenshotsTestInlineCharacterReferencescovers 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,
BenchmarkParsemeasured 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=1on macOS ARM64.The advisory
sizejob already exceeds the 3,840,000-byte ceiling forhello darwin/arm64on forkmain. The CI runs reported 4,393,330 bytes onmainand 4,459,378 bytes on this branch. Baseline size job · Patch size jobLithe tested this branch in a temporary module and adapted the argument order of 16
ui.PopoverWithcalls for the newer fork API. All 12 hover tests and the four screenshot cases passed. The Lithe dependency update will use a forkmaincommit.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.