diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 5efd42f56..2bf01b6d2 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +## 17.1.0 +* [Add syntax highlighting to API docs](https://github.com/fsprojects/FSharp.Formatting/pull/780) + ## 17.0.0 * Update to .NET 7.0.100 diff --git a/build/build.fs b/build/build.fs index 21fe64105..eec34fa93 100644 --- a/build/build.fs +++ b/build/build.fs @@ -103,9 +103,13 @@ let generateDocs _ = ("install --no-cache --version " + release.NugetVersion + " --add-source " + + "\"" + artifactsDir + + "\"" + " --tool-path " + + "\"" + artifactsDir + + "\"" + " fsdocs-tool") |> ignore diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 1f0e022df..db4d83746 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -1877,22 +1877,11 @@ module internal SymbolReader = html.Append("") |> ignore | "code" -> - let lang = - match elem.Attributes("lang") |> Seq.isEmpty with - | true -> "" - | false -> - let lang = elem.Attribute("lang").Value - $"{lang} language-{lang}" + let code = + let code = Literate.ParseMarkdownString("```\n" + elem.Value.TrimEnd('\r', '\n', ' ') + "\n```") + Literate.ToHtml(code, lineNumbers = false) - html.Append("
") |> ignore
-                    html.Append($"") |> ignore
-
-                    let code = elem.Value.TrimEnd('\r', '\n', ' ')
-                    let codeAsHtml = HttpUtility.HtmlEncode code
-                    html.Append(codeAsHtml) |> ignore
-
-                    html.Append("") |> ignore
-                    html.Append("
") |> ignore + html.Append(code) |> ignore // 'a' is not part of the XML doc standard but is widely used | "a" -> html.Append(elem.ToString()) |> ignore // This allows any HTML to be transferred through