Skip to content

fix: preserve line breaks in YAML code blocks (#1463)#1529

Closed
franksong2702 wants to merge 1 commit intonesquena:masterfrom
franksong2702:fix/1463-yaml-linebreaks
Closed

fix: preserve line breaks in YAML code blocks (#1463)#1529
franksong2702 wants to merge 1 commit intonesquena:masterfrom
franksong2702:fix/1463-yaml-linebreaks

Conversation

@franksong2702
Copy link
Copy Markdown
Contributor

Thinking Path

CSS-only bug surfaced during stage-276 triage. After #1400 fixed the parse failed error for YAML code blocks, YAML rendering still appeared flattened — newlines inside fenced YAML blocks were not visible. The issue reporter ran two diagnostic probes (per maintainer guidance):

  1. pre.textContent contains \n characters → renderer pipeline is not dropping newlines
  2. Plain code blocks and language-bash render correctly; only language-yaml is affected

That combination rules out the renderer pipeline, the <pre> user-agent stylesheet, and the .code-tree-wrap CSS. What remains is Prism's YAML tokenizer — it wraps tokens in <span class="token ..."> elements that can set display:inline-block, which collapses perceived line breaks even though the raw text nodes preserve \n.

What Changed

File Change
static/style.css Added 1 rule after the existing language-* background override (line ~737)
.msg-body pre code.language-yaml,
.msg-body pre code.language-yaml .token{white-space:pre !important;}

Forces white-space: pre on both the <code> element and its Prism-generated <span> children, so newlines render visibly regardless of tokenizer-injected display properties.

Why It Matters

YAML is one of the most common LLM output formats (config files, docker-compose, CI pipelines, Kubernetes manifests). Flattened YAML in the chat is not just ugly — it's unreadable. Users copy-paste broken output and waste turns re-requesting formatting.

Verification

  • Full suite pytest tests/ -v — 3935 passed, 3 failed (pre-existing, unrelated)
  • CSS change is additive-only (new selector, no overrides of existing rules)
  • Only language-yaml is targeted — language-bash, language-json, and plain code blocks are unaffected
  • white-space: pre on .token spans does not break single-line YAML (tokens still flow inline; only multi-line content gains visible line breaks)

Risks

Very low. Single CSS selector with !important scoped to .msg-body pre code.language-yaml. No JavaScript changes. No behavior change for non-YAML code blocks.

If Prism's YAML grammar is updated in the future to not inject display:inline-block on tokens, this rule becomes a harmless no-op.

Follow-ups

Model Used

mimo-v2.5-pro (diagnosis + fix) + gpt-5.4-mini (worker execution)

Fixes #1463

Prism's YAML tokenizer wraps tokens in spans that can collapse
newlines via display:inline-block. Force white-space:pre on
language-yaml code blocks and their .token children so multi-line
YAML renders with correct line breaks.

Only language-yaml is affected — bash and other languages already
render correctly.
@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Thanks @franksong2702 — this is the same diagnosis as #1516 with one extra detail (the .token selector also gets white-space: pre, which is the actual fix; the code.language-yaml half is redundant but harmless because Prism wraps everything in tokens).

Two PRs are now open against #1463 — this one and #1516, both yours. Going to consolidate so we don't double-merge:

The .preview-md selector matters — that's the markdown preview panel, and it suffers the same Prism token issue when a YAML block is in a draft message. Going to keep #1516 as the canonical fix and close this one as a duplicate so we keep the broader coverage.

If you'd rather merge the slightly tighter selector here, happy to swap which is the canonical PR — just flag it. Otherwise I'll close this in favor of #1516 in the next release pass.

@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Closing this as superseded by #1516 — both target the YAML newline collapse caused by Prism's token spans, but #1516 also covers the markdown preview panel (.preview-md pre code.language-yaml .token), not just the chat message area (.msg-body). The wider coverage makes #1516 the more complete fix.

The selector-grouping refinement in this PR (combining code + code .token into one rule) is a slight robustness gain, but Prism's tokens are span children of <code>, and <code> already inherits white-space: pre from its <pre> parent — so the additional code selector is redundant. The .token rule cascades correctly without it.

Routing #1516 through the next merge batch. Thanks for both — and for the careful diagnostic write-up. YAML rendering correctly is going to make a noticeable difference for everyone who pastes config files into chat.

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

YAML raw rendering still ignores line breaks after #1400

2 participants