Skip to content

Stop dropping content from pre blocks - #30

Merged
trsdn merged 1 commit into
fix/15-inline-formatting-lists-tablesfrom
fix/19-pre-block-content-loss
Aug 28, 2026
Merged

trsdn merged 1 commit into
fix/15-inline-formatting-lists-tablesfrom
fix/19-pre-block-content-loss

Conversation

@trsdn

@trsdn trsdn commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Fixes #19.

Stacked on #29 (which is stacked on #28). Review those first.

Problem

The <pre> branch resolved a single direct <code> child and converted only that node:

var codeNode = node.SelectSingleNode("code");
ConvertChildren(codeNode ?? node, sb, listDepth, 0, true);

Anything else in the block was silently discarded.

Change

  • Language hint is taken from the first descendant <code> (.//code), so wrapped markup is still recognised.
  • The whole <pre> subtree is converted, so no children are dropped.
  • The fence is sized to be longer than the longest backtick run in the content, instead of always three.

Verification

Input Before After
<pre><code>first</code>\n<code>second</code></pre> first only — second lost first + second
<pre><div><code class="language-py">print(1)</code></div></pre> no language, stray blank line ```py + print(1)
<pre><code> containing ``` 3-backtick fence → broken nested fence 4-backtick fence
<pre><code class="language-cs">…</code></pre> correct unchanged
<pre>raw text</pre> (no <code>) correct unchanged

dotnet build -c Release -r win-x64 succeeds with 0 warnings. The ad-hoc Regex.Match for the language class is now a source-generated regex, consistent with the rest of the file.

The pre branch looked up a single direct <code> child and converted only
that node, so anything else inside the block was discarded: a second
<code> element, a <code> wrapped in a div (which several editors emit),
and text sitting alongside a <code> sibling. The user saw a successful
"Markdown copied" message with code missing from the result.

Take the language hint from the first descendant <code>, but always
convert the whole <pre> subtree so no children are lost. Also size the
fence to be longer than the longest backtick run in the content, which
previously produced a broken nested fence whenever a code block contained
one.

Fixes #19

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b721ad5f-9add-4f55-b9c8-7e6d7b0fb3e7
@trsdn
trsdn merged commit dd325ec into fix/15-inline-formatting-lists-tables Aug 28, 2026
@trsdn
trsdn deleted the fix/19-pre-block-content-loss branch August 28, 2026 21:01
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.

1 participant