Skip to content

Commit

Permalink
Merge pull request #780 from fsprojects/api-highlight
Browse files Browse the repository at this point in the history
Use fssnip highlighter in API docs code examples.
  • Loading branch information
dsyme authored Nov 22, 2022
2 parents c34cbc1 + 94e833a commit 2cda5a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ let generateDocs _ =
("install --no-cache --version "
+ release.NugetVersion
+ " --add-source "
+ "\""
+ artifactsDir
+ "\""
+ " --tool-path "
+ "\""
+ artifactsDir
+ "\""
+ " fsdocs-tool")
|> ignore

Expand Down
19 changes: 4 additions & 15 deletions src/FSharp.Formatting.ApiDocs/GenerateModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1877,22 +1877,11 @@ module internal SymbolReader =

html.Append("</code>") |> 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("<pre>") |> ignore
html.Append($"<code class=\"{lang}\">") |> ignore

let code = elem.Value.TrimEnd('\r', '\n', ' ')
let codeAsHtml = HttpUtility.HtmlEncode code
html.Append(codeAsHtml) |> ignore

html.Append("</code>") |> ignore
html.Append("</pre>") |> 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
Expand Down

0 comments on commit 2cda5a9

Please sign in to comment.