fix: YAML code blocks collapse newlines due to Prism token white-space (#1463)#1516
Merged
1 commit merged intonesquena:masterfrom May 3, 2026
Merged
Conversation
nesquena#1463) Prism's YAML grammar wraps tokens in <span> elements where white-space defaults to normal, collapsing \n characters into spaces. The DOM textContent is correct (confirmed by reporter's probe), so the bug is purely CSS. Force white-space:pre on .token elements inside language-yaml code blocks for both .msg-body and .preview-md contexts.
Collaborator
|
Right layer for the fix. The reporter's probes on #1463 closed the diagnosis loop:
A CSS override scoped to A couple of review notes:
Pulling locally to verify against the reporter's repro. Thanks @franksong2702. |
This was referenced May 3, 2026
f8ed6da
sunnysktsang
pushed a commit
to sunnysktsang/hermes-webui
that referenced
this pull request
May 3, 2026
…h newlines (Prism token white-space) — closes nesquena#1463
sunnysktsang
pushed a commit
to sunnysktsang/hermes-webui
that referenced
this pull request
May 3, 2026
…sorbed CHANGELOG, ROADMAP, TESTING bumped (3936 \u2192 3946). 8 constituent PRs: - nesquena#1523 (@franksong2702) branch indicator codepoint fix - nesquena#1519 (@franksong2702) onboarding API-key focus loss fix - nesquena#1518 (@franksong2702) voice-mode toggle-off recognizer stop - nesquena#1516 (@franksong2702) YAML newline CSS rules - nesquena#1517 (@franksong2702) __CACHE_VERSION__ \u2192 __WEBUI_VERSION__ rename - nesquena#1532 (@ai-ag2026) state.db WebUI session recovery - nesquena#1525 (@ai-ag2026) stale stream state proactive cleanup - nesquena#1526 (@ai-ag2026) max_tokens forwarding + OpenRouter quota classifier Opus MUST-FIX absorbed: sw.js conflict-marker cleanup + regression guard. Opus SHOULD-FIX deferred to follow-up nesquena#1533 (race in _clear_stale_stream_state). 2 closed as duplicates: nesquena#1528 (identical to nesquena#1517), nesquena#1529 (superseded by nesquena#1516). 1 maintainer-review label: nesquena#1531 (Asunfly stowaway change in force-push). 5 stay on hold: nesquena#1418 nesquena#1464 nesquena#1404 nesquena#1353 nesquena#1311.
This was referenced May 4, 2026
bergeouss
pushed a commit
to bergeouss/hermes-webui
that referenced
this pull request
May 4, 2026
…/ nesquena#1463) Closes nesquena#1618 (reported by @Zixim) and corrects nesquena#1463's previous fix. Bug: YAML, JSON, and diff/patch fenced code blocks render flattened to a single line. Reporter noted the bug persisted v0.50.279 -> v0.50.291 -> v0.50.292 despite PR nesquena#1516's CSS-only "fix". Root cause: PR nesquena#484 (v0.50.237) added a JSON/YAML tree-viewer that routes those languages through <div class="code-tree-wrap">...<pre class="tree-raw-view"> instead of bare <pre>. Same release added the diff/patch coloring path that emits <pre class="diff-block">. The _pre_stash regex at static/ui.js:1914 matched only literal <pre> with no attributes: <pre>[\s\S]*?<\/pre> Both new shapes failed to match, fell through to the paragraph-wrap pass, and \n characters inside the code blocks got replaced with <br> tags inside <code>. By the time Prism ran, no newlines remained for the CSS rule (PR nesquena#1516, language-yaml .token { white-space: pre !important }) to preserve. Fix: relax the regex to accept any attribute on <pre>: <pre>[\s\S]*?<\/pre> -> <pre[^>]*>[\s\S]*?<\/pre> One regex character. Pulls JSON, YAML, and diff/patch blocks into the stash so paragraph-wrap can't mangle them. Bash, Python, Go, etc. were never affected because they emit bare <pre>. Tests: 9 new (2 source-string invariants + 7 behavioural via node-driver against the actual static/ui.js renderMd()). 6 of the 7 behavioural tests fail on master and pass with the fix; the 3 sanity checks (yml-alias, bash, mermaid) pass on both. Plus widened source-scan window in 3 pre-existing test_745 assertions from 400 to 1500 chars. The new comment block above the fixed regex pushed it past the previous scan window. Pure window-narrowness bug, not a behavior regression. 4245 -> 4254 passing.
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.
Thinking Path
textContentof YAML blocks preserves\ncharacters, ruling out the renderer pipelinelanguage-bashblocks render correctly — onlylanguage-yamlis affected<span>elements wherewhite-spacedefaults tonormal, collapsing newlines into spaceswhite-space: preon token spans inside YAML code blocksWhat Changed
Added two CSS rules to
static/style.css:Covers both the chat message area (
.msg-body) and the markdown preview panel (.preview-md).Why It Matters
YAML is one of the most common code-block languages in this UI (config files, docker-compose, CI pipelines). Collapsed newlines make YAML blocks unreadable — the indentation structure that YAML depends on is lost.
Verification
\npresent in DOMtextContent→ CSS fix is the correct layerlanguage-bashwork → scoped to YAML token processing only.language-yaml .tokenis specific enough to avoid side effects on other languages!importantis necessary because Prism's bundled themes setwhite-spaceon token elementsRisks / Follow-ups
language-yamlonly; other languages are unaffected.Model Used