8000 [Repo Assist] Fix crash in Markdown.ToMd when document contains indirect images by github-actions[bot] · Pull Request #1094 · fsprojects/FSharp.Formatting · GitHub
[go: up one dir, main page]

Skip to content

[Repo Assist] Fix crash in Markdown.ToMd when document contains indirect images#1094

Merged
dsyme merged 2 commits intomainfrom
repo-assist/fix-indirect-image-tomkd-crash-e646dcd01db86a28
Mar 17, 2026
Merged

[Repo Assist] Fix crash in Markdown.ToMd when document contains indirect images#1094
dsyme merged 2 commits intomainfrom
repo-assist/fix-indirect-image-tomkd-crash-e646dcd01db86a28

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated PR from Repo Assist.

Problem

Markdown.ToMd (and any pipeline that serialises a parsed Markdown AST back to Markdown text, such as OutputKind.Markdown literate output) would throw System.Exception: tbd - IndirectImage when the document contained a reference-style image:

![alt text][image-id]

[image-id]: (example.com/redacted) "Title"

The crash came from MarkdownUtils.fs — the formatSpan function had a failwith "tbd - IndirectImage" placeholder for both arms of the IndirectImage case:

| IndirectImage(_body, _, LookupKey ctx.Links (_link, _), _)
| IndirectImage(_body, _link, _, _) -> failwith "tbd - IndirectImage"

Fix

Implement IndirectImage serialisation by analogy with IndirectLink (which already handles both the resolved and unresolved cases):

Case Old behaviour New behaviour
Reference key found in links dict 💥 failwith "tbd" ![alt](resolved-url) (promote to direct image)
Reference key not found 💥 failwith "tbd" ![alt][key] (preserve original indirect form)

Root cause

The IndirectImage case was left as a tbd stub when the Markdown-to-Markdown formatting was originally written. All other span types were already handled.

Test status

  • dotnet build FSharp.Formatting.sln --configuration Release — succeeded (0 errors, 1 pre-existing FS0760 warning)
  • dotnet test tests/FSharp.Markdown.Tests/ — 259 passed, 0 failed (+2 new tests covering both cases)
  • dotnet fantomas src/FSharp.Formatting.Markdown/MarkdownUtils.fs tests/FSharp.Markdown.Tests/Markdown.fs --check — no formatting changes needed

Files changed

File Change
src/FSharp.Formatting.Markdown/MarkdownUtils.fs Fix IndirectImage in formatSpan — two lines replacing the failwith
tests/FSharp.Markdown.Tests/Markdown.fs Add two regression tests
RELEASE_NOTES.md Add entry under [Unreleased]

Generated by Repo Assist ·

Generated by Repo Assist ·

To install this agentic workflow, run

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

Markdown.ToMd (formatAsMarkdown) called formatSpan in MarkdownUtils.fs
which had a failwith "tbd - IndirectImage" for both arms of IndirectImage.
This caused any call to Markdown.ToMd on a document containing

Fix: implement the two cases by analogy with IndirectLink:
  (preserving the original indirect form)

Add two regression tests in FSharp.Markdown.Tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme merged commit 0e46e50 into main Mar 17, 2026
4 checks passed
@dsyme dsyme deleted the repo-assist/fix-indirect-image-tomkd-crash-e646dcd01db86a28 branch March 17, 2026 00:11
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.

1 participant

0