Skip to content

Commit

Permalink
Merge pull request #762 from yazeedobaid/main
Browse files Browse the repository at this point in the history
Add HTML code element for code samples to enable syntax highlight.
  • Loading branch information
dsyme authored Aug 15, 2022
2 parents a55c29b + 2a66e84 commit 3d77b09
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 3d77b09

Please sign in to comment.