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

Add HTML code element for code samples to enable syntax highlight. #762

Merged
merged 1 commit into from
Aug 15, 2022
Merged
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
8 changes: 8 additions & 0 deletions src/FSharp.Formatting.ApiDocs/GenerateModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1938,12 +1938,20 @@ 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}"
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
// 'a' is not part of the XML doc standard but is widely used
| "a" -> html.Append(elem.ToString()) |> ignore
Expand Down