Skip to content

Commit 81a4513

Browse files
authored
Merge pull request #1203 from fsprojects/repo-assist/fix-tomd-anchorlink-2026-05-09-2996e460-bd5537e212ac14c5
[Repo Assist] fix: Markdown.ToMd serialises AnchorLink spans as inline HTML anchor
2 parents 4605a3f + 3f4a5c5 commit 81a4513

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Fix `Markdown.ToLatex` producing invalid LaTeX output for level-6 (and deeper) headings. Previously the LaTeX command was an empty string, resulting in bare `{content}` without a command prefix. Headings at level 6+ are now serialised as `\subparagraph{...}`, which is the deepest sectioning command available in LaTeX.
2222
* Fix `Markdown.ToMd` multi-paragraph blockquote round-trip. The old code emitted a bare blank line between inner paragraphs, which CommonMark parses as closing the blockquote, resulting in multiple separate blockquotes on re-parse. Paragraph separators inside a blockquote are now emitted as `>` (an empty blockquote continuation line) so the round-trip preserves a single `QuotedBlock`.
2323
* Fix `Markdown.ToMd` serialising unresolved indirect links as `[body](key)` (treating the reference key as a URL) instead of the correct `[body][key]` form. Unresolved indirect links are now preserved in their original indirect-reference form, consistent with how unresolved indirect images are handled.
24+
* Fix `Markdown.ToMd` silently dropping `AnchorLink` spans. Named anchors (used by the API documentation generator to create in-page navigation targets) are now serialised as `<a name="..."></a>` inline HTML, so they survive a round-trip and remain functional when the output is later converted to HTML.
2425

2526
### Added
2627
* Introduce `--panel-background` and `--panel-border` CSS custom properties in `fsdocs-default.css`. These decouple panel/component colours (copy-code button, blockquotes, sidebar, page menu, dialogs, tooltips, API tables) from `--header-background`/`--header-border`. Both variables default to the header values, so existing themes are unaffected; themes that need a different colour for content panels can now override `--panel-background` and `--panel-border` independently. [#1156](https://github.com/fsprojects/FSharp.Formatting/issues/1156)

src/FSharp.Formatting.Markdown/MarkdownUtils.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ module internal MarkdownUtils =
104104
| Literal(str, _) -> str
105105
| HardLineBreak(_) -> " " + ctx.Newline
106106

107-
| AnchorLink _ -> ""
107+
| AnchorLink(link, _) -> sprintf "<a name=\"%s\"></a>" link
108108
| DirectLink(body, link, title, _) ->
109109
let t =
110110
title

tests/FSharp.Markdown.Tests/Markdown.fs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,3 +2141,20 @@ let ``ToMd serialises single-line equation block as compact dollar-dollar notati
21412141
let result = Markdown.ToMd(doc, newline = "\n")
21422142
result |> should contain "$$E = mc^2$$"
21432143
result |> should not' (contain "\\begin{equation}")
2144+
2145+
[<Test>]
2146+
let ``ToMd serialises AnchorLink as inline HTML anchor`` () =
2147+
// AnchorLink spans must not be silently dropped — they should be emitted as <a name="…"></a>
2148+
// so that named anchors survive a ToMd round-trip and remain functional when later converted to HTML.
2149+
let doc =
2150+
MarkdownDocument(
2151+
[ Paragraph(
2152+
[ AnchorLink("my-anchor", MarkdownRange.zero); Literal("text", MarkdownRange.zero) ],
2153+
MarkdownRange.zero
2154+
) ],
2155+
dict []
2156+
)
2157+
2158+
let result = Markdown.ToMd(doc, newline = "\n")
2159+
result |> should contain "<a name=\"my-anchor\"></a>"
2160+
result |> should contain "text"

0 commit comments

Comments
 (0)