Skip to content

[Repo Assist] fix: Markdown.ToMd uses correct backtick fence for inline code containing backticks#1147

Open
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-tomd-inlinecode-backtick-2026-04-06-26b7575241bce079
Open

[Repo Assist] fix: Markdown.ToMd uses correct backtick fence for inline code containing backticks#1147
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-tomd-inlinecode-backtick-2026-04-06-26b7575241bce079

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

🤖 This is an automated PR from Repo Assist.

Problem

Markdown.ToMd always wrapped InlineCode spans with a single backtick:

| InlineCode(body, _) -> "`" + body + "`"

When body itself contains backtick characters this produces invalid Markdown. For example, InlineCode("ab", _)serialised to ``ab , which a parser would read as the empty span a followed by literal `b` ` `` — not the intended inline code.

The fsdocs inline parser already supports N-backtick fences (List.DelimitedNTimes) and the backtick-with-spaces form, so a serialiser that produces multi-backtick fences round-trips correctly.

Fix

MarkdownUtils.formatSpan for the InlineCode case now:

  1. Counts the longest run of consecutive backtick characters in the body.
  2. Uses a fence of (run + 1) backticks — guaranteeing the delimiter never appears inside the body.
  3. Adds a leading/trailing space when the body itself starts or ends with a backtick, to prevent fence ambiguity (per CommonMark spec).

Changes

File Change
src/FSharp.Formatting.Markdown/MarkdownUtils.fs Replace single-backtick InlineCode serialisation with adaptive fence
tests/FSharp.Markdown.Tests/Markdown.fs Add two round-trip tests: single-backtick and double-backtick body content
RELEASE_NOTES.md Changelog entry under [Unreleased] / Fixed

Test Status

  • dotnet build FSharp.Formatting.sln --configuration Release — 0 warnings, 0 errors
  • dotnet test tests/FSharp.Markdown.Tests --configuration Release --no-build283/283 passed (includes 2 new tests)
  • dotnet test FSharp.Formatting.sln --configuration Release --no-build — full suite passes (fsdocs-tool: 12, CodeFormat: 30, Literate: 143, ApiDocs: 88, Markdown: 283)
  • dotnet fantomas … --check — formatting unchanged

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

…ackticks

When InlineCode body contains backtick characters, the previous
single-backtick wrapping produced invalid Markdown that would not
re-parse as the original inline code span.

Fix: compute the longest run of consecutive backticks in the body and
use a fence of (run + 1) backticks. When the body starts or ends with
a backtick, add surrounding spaces so the fence and body do not merge.

Add two round-trip tests covering single-backtick and double-backtick
content.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review April 7, 2026 17:02
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