Skip to content

Commit 0b91a3f

Browse files
fix: Markdown.ToMd serialises AnchorLink as inline HTML anchor
Previously AnchorLink spans were silently dropped (rendered as ""). Named anchors are now emitted as <a name="..."></a> inline HTML so they survive a ToMd round-trip and remain functional when the output is later converted to HTML. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2204eb9 commit 0b91a3f

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
@@ -20,6 +20,7 @@
2020
* Remove stray `printfn` debug output emitted to stdout when `Markdown.ToMd` encountered an unrecognised paragraph type.
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` 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.
23+
* 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.
2324

2425
### Added
2526
* 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
@@ -2056,3 +2056,20 @@ let ``ToMd serialises single-line equation block as compact dollar-dollar notati
20562056
let result = Markdown.ToMd(doc, newline = "\n")
20572057
result |> should contain "$$E = mc^2$$"
20582058
result |> should not' (contain "\\begin{equation}")
2059+
2060+
[<Test>]
2061+
let ``ToMd serialises AnchorLink as inline HTML anchor`` () =
2062+
// AnchorLink spans must not be silently dropped — they should be emitted as <a name="…"></a>
2063+
// so that named anchors survive a ToMd round-trip and remain functional when later converted to HTML.
2064+
let doc =
2065+
MarkdownDocument(
2066+
[ Paragraph(
2067+
[ AnchorLink("my-anchor", MarkdownRange.zero); Literal("text", MarkdownRange.zero) ],
2068+
MarkdownRange.zero
2069+
) ],
2070+
dict []
2071+
)
2072+
2073+
let result = Markdown.ToMd(doc, newline = "\n")
2074+
result |> should contain "<a name=\"my-anchor\"></a>"
2075+
result |> should contain "text"

0 commit comments

Comments
 (0)