Skip to content

[Repo Assist] fix: Markdown.ToMd preserves [body][key] form for unresolved indirect links#1185

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-tomd-indirect-link-2026-04-23-62a1bff0a95d549c
Draft

[Repo Assist] fix: Markdown.ToMd preserves [body][key] form for unresolved indirect links#1185
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-tomd-indirect-link-2026-04-23-62a1bff0a95d549c

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

Summary

Fixes an inconsistency in Markdown.ToMd where unresolved indirect links were serialised as broken direct links [body](key) instead of the correct indirect form [body][key].

Root Cause

In MarkdownUtils.fs, formatSpan had a combined case for IndirectLink:

| IndirectLink(body, _, LookupKey ctx.Links (link, _), _)
| IndirectLink(body, link, _, _) -> "[" + formatSpans ctx body + "](" + link + ")"

When the reference key was not in ctx.Links, the second pattern matched with link bound to the original field — the raw reference text, not a URL. This produced [body](original) which treats the reference key as a URL, breaking the link.

Compare with IndirectImage, which already handled this correctly:

| IndirectImage(body, _, LookupKey ctx.Links (link, _), _) -> sprintf "![%s](%s)" body link
| IndirectImage(body, _, key, _) -> sprintf "![%s][%s]" body key  // ← preserves indirect form

Fix

Split the two IndirectLink cases to match the IndirectImage pattern:

| IndirectLink(body, _, LookupKey ctx.Links (link, _), _) -> "[" + formatSpans ctx body + "](" + link + ")"
| IndirectLink(body, _, key, _) -> "[" + formatSpans ctx body + "][" + key + "]"

Resolved links still produce a direct link (downconversion); unresolved links now preserve the [body][key] indirect form.

Changes

  • src/FSharp.Formatting.Markdown/MarkdownUtils.fs — fix IndirectLink fallback case
  • tests/FSharp.Markdown.Tests/Markdown.fs — add test ToMd preserves indirect link form when key is unresolved
  • RELEASE_NOTES.md — changelog entry under [Unreleased] → Fixed

Test Status

dotnet build FSharp.Formatting.sln --configuration Release — 0 errors, 0 warnings
dotnet test tests/FSharp.Markdown.Tests --configuration Release --no-build347/347 passed (includes new test)

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

… links

Previously the unresolved-key fallback for IndirectLink used the second
field (original) as a direct-link URL, producing '[body](key)' which treats
the reference key as a URL. This was inconsistent with IndirectImage, which
preserves '![body][key]' when the key is unresolved.

Fix: split the two IndirectLink cases so the resolved path produces a direct
link '[body](url)' and the unresolved path preserves the indirect form
'[body][key]', matching IndirectImage behaviour.

Added test: 'ToMd preserves indirect link form when key is unresolved'
(347/347 Markdown tests pass).

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