Skip to content

[Repo Assist] fix: use ctx.Newline in ToMd table rows and ToFsx output comments#1195

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-tomd-table-newline-2026-04-30-75eda8dc66e94bc8
Draft

[Repo Assist] fix: use ctx.Newline in ToMd table rows and ToFsx output comments#1195
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-tomd-table-newline-2026-04-30-75eda8dc66e94bc8

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

Summary

Two targeted bug fixes for hardcoded "\n" newline usage in the Markdown serialisers.


1. Markdown.ToMdTableBlock rows used hardcoded "\n" (Task 3 — bug fix)

Root cause

formatParagraph for TableBlock collected all data rows into a single string with String.concat "\n", then yielded that one big string. The trailing blank-line was emitted as yield "\n" (a literal newline character string) rather than the standard yield "" (empty-line sentinel) used by all other paragraph types.

Effect

On Windows (ctx.Newline = "\r\n"), Markdown.ToMd produced mixed line endings in the output: headers and alignments used \r\n (from the outer String.concat newline), while data rows used \n (from the hardcoded String.concat "\n" inside). The trailing blank was also a bare \n.

Fix (src/FSharp.Formatting.Markdown/MarkdownUtils.fs)

  • Replaced the single-yield [for r in rows ...] |> String.concat "\n" with a for r in rows do yield ... loop, so each data row is emitted as a separate string item.
  • Changed yield "\n"yield "", consistent with all other paragraph types.

The outer String.concat newline in formatAsMarkdown now correctly joins data rows with the configured newline.


2. Markdown.ToFsx — output-comment used hardcoded "\n" (Task 5 — coding improvement)

Root cause

FsxFormatting.fs opened the (* output: ...*) comment with a literal "\n":

| _out -> "(* output: \n" + output + "*)")

The output string was already built with ctx.Newline, but the opening comment-marker used a Unix newline regardless.

Fix (src/FSharp.Formatting.Markdown/FsxFormatting.fs)

  • Changed "(* output: \n""(* output: " + ctx.Newline so the entire comment uses consistent line endings.

Tests added (tests/FSharp.Markdown.Tests/Markdown.fs)

  • ToMd table rows each appear on their own line — parses a two-row table, serialises with newline = "\n", and asserts the non-blank lines equal exactly 4 (header + separator + 2 data rows).
  • ToMd table row count is correct when Windows newline is used — regression test: serialises with newline = "\r\n" and asserts there are no stray \n embedded in the output (no \r\n\n or \n\r\n sequences).

Test Status

  • dotnet build FSharp.Formatting.sln --configuration Release — succeeded (0 warnings, 0 errors)
  • dotnet test tests/FSharp.Markdown.Tests348/348 passed (includes 2 new tests)
  • dotnet fantomas ... --check — formatting verified (no changes needed)
  • dotnet test FSharp.Formatting.sln --configuration Release --no-build — full suite passes (Literate: 143, ApiDocs: 88+4 skipped, CodeFormat: 30, fsdocs-tool: 12, Markdown: 348)

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

To install this agentic workflow, run

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

Previously, the TableBlock serialiser in MarkdownUtils.fs joined all data
rows into a single string using String.concat "\\n" (hardcoded Unix newline),
and then emitted a literal "\n" string as the trailing blank line sentinel.
On Windows (ctx.Newline = "\r\n") this produced mixed line endings in the
ToMd output.

This commit refactors the TableBlock case to yield each data row as a
separate string (consistent with every other paragraph type), so the outer
String.concat newline in formatAsMarkdown applies the correct separator.
The trailing blank line now uses the standard "" empty-line sentinel.

FsxFormatting.fs had the same kind of issue: the (\* output: ...*) comment
wrapper used a literal "\n" to open the comment block.  It now uses
ctx.Newline so both the opening and the content use consistent line endings.

Two new unit tests cover the table row count and the Windows regression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants