Conversation
…<pre> Elements nested multiple levels deep inside a <pre> block could have newlines and indentation inserted between them during serialization. This corrupted output from syntax highlighters (e.g. shiki) that emit <pre><code><span class="line"><span>...</span></span></code></pre>. Root cause: the serialize function did not propagate an 'insidePre' context to descendant elements. When a non-pre element with multiple element children (onlyText = false) appeared inside <pre>, the canAddNewLine flag on sibling elements caused newLines to be inserted. Fix: add an 'insidePre' parameter to serialize. When true, all newline/indentation formatting is suppressed regardless of element type. Closes #1509 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Feb 22, 2026
dsyme
approved these changes
Feb 22, 2026
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.
🤖 Repo Assist here — I'm an automated AI assistant for this repository.
Closes #1509Problem
When
HtmlNode.ToString()serializes a<pre>block, newlines and indentation can be incorrectly inserted into elements nested multiple levels deep inside<pre>. This corrupts output from syntax highlighters (e.g. shiki) that emit HTML like:In this case, the
<code>element (which hasonlyText = false) would have a newline inserted after<code>, and the<span>elements inside<span class="line">would also have newlines inserted between them — corrupting the output.Root Cause
The
serializefunction inHtmlNode.fshandled the<pre>tag itself correctly (skipping formatting for its direct children via theisPreTagflag), but did not propagate any "inside pre" context to deeper descendants. When a non-pre element with multiple element children (onlyText = false) appeared inside<pre>, thecanAddNewLineflag on sibling elements causednewLinecalls.Fix
Add an
insidePreparameter toserialize. Whentrue, all newline/indentation formatting is suppressed regardless of element type. The value is set totruewhen entering a<pre>element and propagated to all recursive calls:The single-level case (spans directly inside
<pre>) was already handled correctly by the existingisPreTag/onlyTextchecks; this fix extends that handling to all depths.Test
Added regression test
Maintain whitespace in deeply nested elements inside pre through round-tripinHtmlParser.fscovering the shiki-style deeply nested structure.Test Status
dotnet build src/FSharp.Data.Html.Core/)FSharp.Data.Core.Testspass (including the new regression test and all 10 existing whitespace-related tests)FSharp.Data.Testscould not be built: the WorldBank type provider requires network access toapi.worldbank.org, which is blocked by the build environment's network proxy — unrelated to this change.Warning
The following domain was blocked by the firewall during workflow execution:
www.google.com