Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fssnip highlighter in API docs code examples. #780

Merged
merged 5 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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