fix: preserve YAML code block newlines#1641
fix: preserve YAML code block newlines#1641Michaelyklam wants to merge 1 commit intonesquena:masterfrom
Conversation
|
Thanks @Michaelyklam — went through this carefully and I'm afraid this PR is being superseded by PR #1642 (filed by us 4 minutes after yours). It's the exact same one-character regex relax for - s=s.replace(/(<div class="pre-header">[\s\S]*?<\/div>)?<pre>[\s\S]*?<\/pre>...
+ s=s.replace(/(<div class="pre-header">[\s\S]*?<\/div>)?<pre[^>]*>[\s\S]*?<\/pre>...We hit this independently in our investigation of #1618 (the @Zixim "still flattened in v0.50.291" report) — both arrived at the same minimal-surface fix, which is encouraging convergent evidence that this IS the right layer. Why we're shipping #1642 instead:
Adopting your evidence in-tree: your before/after screenshots ( Closing this PR but the work is being shipped — your fix shape, your tests, and your media are all part of the v0.50.295 release. Thanks for the parallel diagnosis and for the strong contributor pattern this week. |
…chaelyklam nesquena#1641) Adopt the UI media from @Michaelyklam's parallel-discovery PR nesquena#1641 which shipped the same one-character regex relax fix for nesquena#1618. PR nesquena#1641 is being closed as superseded by nesquena#1642 (which carries nesquena APPROVED + 322 LOC test suite); preserving Michael's UI evidence here so the visual proof of the fix lives in-tree alongside the canonical PR. Co-authored-by: Michael Lam <[email protected]>
Constituent PRs: nesquena#1637 by @Michaelyklam — protect raw pre from glued-bold lift (closes nesquena#1451) nesquena#1639 by @bergeouss — macOS auto-scroll race + custom:* provider list (closes nesquena#1360, nesquena#1619) nesquena#1642 by @nesquena-hermes — YAML/JSON/diff code block newlines (closes nesquena#1618, nesquena#1463) Opus advisor SHIP verdict on stage-295. One observation absorbed: - api/config.py:2533 dead-code comment per Opus (defensive belt-and-braces for nesquena#1619 fallback; load-bearing fix is in routes.py /api/models/live) PR nesquena#1641 (Michaelyklam parallel-discovery duplicate of nesquena#1642) closed as superseded; UI media adopted with co-author trailer. 4245 → 4255 tests passing (+10).
Thinking Path
<pre>elements with classes, but the paragraph-protection stash only matched literal<pre>.<pre class="tree-raw-view">and<pre class="diff-block">were not stashed, paragraph wrapping converted their internal newlines into<br>before Prism/rendering could preserve them.<pre>blocks too, keeping the fix to the smallest affected renderer primitive.Fixes #1618
What Changed
static/ui.jsfrom<pre>to<pre[^>]*>so attributed code blocks are protected before paragraph wrapping.renderMd()implementation and assert YAML tree raw views and diff blocks keep newline characters inside<code>.Why It Matters
YAML, diff, JSON, and similar code blocks are only useful if their structure survives rendering. Flattening YAML into one line changes the meaning and makes copied examples harder to read or use. Protecting attributed
<pre>blocks fixes the current YAML bug and prevents the same paragraph wrapping path from mangling other classed code blocks.Verification
Result:
Manual verification:
textContentwas flattened andinnerHTMLcontained<br>insidecode.language-yaml.textContentcontains real newlines,innerHTMLdoes not contain<br>, and the rendered block is multi-line with indentation preserved.UI media:
Before — YAML block flattened into one line:
After — YAML line breaks and indentation preserved:
Risks / Follow-ups
<pre>blocks, which matches the behavior already used by the autolink stash and keeps code-block internals out of paragraph wrapping.code-tree-wrapHTML can still be wrapped by an outer paragraph in the string output; this PR fixes the newline-loss bug without widening scope into renderer markup normalization.PytestUnknownMarkWarning: Unknown pytest.mark.integration.Model Used
AI assisted.
gpt-5.5