Skip to content

[Repo Assist] fix: Markdown.ToMd preserves indented code blocks as fenced code blocks#1134

Open
github-actions[bot] wants to merge 3 commits intomainfrom
repo-assist/fix-tomd-indented-codeblock-2026-04-02-6bcfba2818b0ad17
Open

[Repo Assist] fix: Markdown.ToMd preserves indented code blocks as fenced code blocks#1134
github-actions[bot] wants to merge 3 commits intomainfrom
repo-assist/fix-tomd-indented-codeblock-2026-04-02-6bcfba2818b0ad17

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 2, 2026

🤖 This PR was created by Repo Assist, an automated AI assistant.

Root Cause

Markdown.ToMd serialised CodeBlock nodes with fence = None (indented code blocks) as bare text:

// Before
match fence with
| None -> ()          // no opening fence
| Some f -> yield f + language
yield code
match fence with
| None -> ()          // no closing fence
| Some f -> yield f
yield ""
```

An indented code block like:
```
    let x = 1
    let y = 2

…was serialised as just "let x = 1\nlet y = 2\n". When re-parsed, this is a Paragraph, not a CodeBlock — breaking the round-trip.

Fix

Use triple-backtick fences for all code blocks, falling back to ``` when the original had no fence:

// After
let f = defaultArg fence "```"
yield f + language
yield code
yield f
yield ""

This produces a valid fenced code block for both fenced and formerly-indented inputs. Fenced code blocks render identically to indented code blocks in all standard Markdown renderers.

Changes

File Change
src/FSharp.Formatting.Markdown/MarkdownUtils.fs Use defaultArg fence "```" for CodeBlock serialisation
tests/FSharp.Markdown.Tests/Markdown.fs New round-trip test for indented code blocks
RELEASE_NOTES.md Changelog entry under [Unreleased]

Test Status

  • dotnet build FSharp.Formatting.sln --configuration ReleaseBuild succeeded, 0 warnings
  • dotnet test tests/FSharp.Markdown.Tests282/282 passed (includes 1 new test)
  • dotnet test FSharp.Formatting.sln --configuration Release --no-build — full suite passes (ApiDocs: 88/92; Literate: 120/120; CodeFormat: 30/32; fsdocs-tool: 8/8)

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@e1ecf341a90b7bc2021e77c58685d7e269e20b99

Indented code blocks (parsed with fence = None) were serialised by
Markdown.ToMd as bare text without any code block markers. When the
output was re-parsed, the content was interpreted as a Paragraph, not
a CodeBlock — breaking the round-trip.

Fix: use triple-backtick fences for code blocks that originally had no
fence, ensuring the serialised form is always a valid fenced code block.
Fenced code blocks round-trip correctly and render identically to
indented code blocks in all Markdown renderers.

Added a round-trip test to cover the case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review April 2, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants