@@ -16,6 +16,8 @@ open FSharp.Patterns
1616/// XML documentation comment reading and combining utilities.
1717[<AutoOpen>]
1818module internal XmlDocReader =
19+ /// Normalises leading whitespace from a multi-line XML doc comment string, removing
20+ /// the common indentation prefix that .NET compilers emit.
1921 let removeSpaces ( comment : string ) =
2022 use reader = new StringReader( comment)
2123
@@ -28,6 +30,10 @@ module internal XmlDocReader =
2830
2931 String.removeSpaces lines
3032
33+ /// Converts a Markdown-style literate document (used when a doc comment was written as
34+ /// free Markdown text) into an <see cref =" T:FSharp.Formatting.ApiDocs.ApiDocComment " />.
35+ /// Sections headed with <c >## Returns</c >, <c >## Examples</c >, <c >## Notes</c >, and
36+ /// <c >## Remarks</c > are mapped to the corresponding ApiDocComment fields.
3137 let readMarkdownCommentAsHtml el ( doc : LiterateDocument ) =
3238 let groups = System.Collections.Generic.List<(_ * _)>()
3339
@@ -107,6 +113,8 @@ module internal XmlDocReader =
107113 rawData = raw
108114 )
109115
116+ /// Tries to parse a <c >[ key: value ] </c > command embedded inside an XML doc text node.
117+ /// Returns <c >Some (key, value)</c > on success or <c >None</c > if the text is not a command.
110118 let findCommand cmd =
111119 match cmd with
112120 | StringPosition.StartsWithWrapped ( " [" , " ]" ) ( ParseCommand( k, v), _ rest) -> Some( k, v)
@@ -137,6 +145,11 @@ module internal XmlDocReader =
137145 else
138146 $" <pre>%s {trimmed}</pre>"
139147
148+ /// Recursively converts an <see cref =" T:System.Xml.Linq.XElement " /> to an HTML string,
149+ /// resolving <c >< ; see cref="…"/> ; </c > references via <paramref name =" urlMap " /> and
150+ /// collecting any embedded <c >[ key: value ] </c > commands into <paramref name =" cmds " />.
151+ /// When <paramref name =" anyTagsOK " /> is <c >true</c >, unknown XML elements are passed
152+ /// through as raw HTML; otherwise they are silently dropped.
140153 let rec readXmlElementAsHtml
141154 anyTagsOK
142155 ( urlMap : CrossReferenceResolver )
@@ -217,12 +230,20 @@ module internal XmlDocReader =
217230 let elemAsXml = elem.ToString()
218231 html.Append( elemAsXml) |> ignore
219232
233+ /// Active pattern that matches a <c >< ; summary> ; </c > element that contains only text
234+ /// (no child elements). Used to take a fast path that avoids the full HTML builder.
220235 let (| SummaryWithoutChildren | _ |) ( e : XElement ) =
221236 if e.Name.LocalName = " summary" && not e.HasElements then
222237 Some e
223238 else
224239 None
225240
241+ /// Core function that processes a standard C#/F# XML documentation element (the root
242+ /// <c >< ; member …> ; </c > or <c >< ; doc> ; </c > element) into an
243+ /// <see cref =" T:FSharp.Formatting.ApiDocs.ApiDocComment " /> plus an optional list of
244+ /// <c >< ; namespacedoc> ; </c > sub-elements (for namespace-level summaries).
245+ /// When <paramref name =" summaryExpected " /> is <c >true</c >, a missing <c >< ; summary> ; </c >
246+ /// child is treated as raw HTML content.
226247 let readXmlCommentAsHtmlAux
227248 summaryExpected
228249 ( urlMap : CrossReferenceResolver )
@@ -409,15 +430,22 @@ module internal XmlDocReader =
409430
410431 comment, nsels
411432
433+ /// Concatenates the HTML text of two <see cref =" T:FSharp.Formatting.ApiDocs.ApiDocHtml " /> values,
434+ /// separated by a newline.
412435 let combineHtml ( h1 : ApiDocHtml ) ( h2 : ApiDocHtml ) =
413436 ApiDocHtml( String.concat " \n " [ h1.HtmlText; h2.HtmlText ], None)
414437
438+ /// Combines two optional <see cref =" T:FSharp.Formatting.ApiDocs.ApiDocHtml " /> values:
439+ /// returns the non-<c >None</c > side, or concatenates both when both are present.
415440 let combineHtmlOptions ( h1 : ApiDocHtml option ) ( h2 : ApiDocHtml option ) =
416441 match h1, h2 with
417442 | x, None -> x
418443 | None, x -> x
419444 | Some x, Some y -> Some( combineHtml x y)
420445
446+ /// Merges two <see cref =" T:FSharp.Formatting.ApiDocs.ApiDocComment " /> values by
447+ /// concatenating their HTML sections (summary, remarks, parameters, examples, etc.).
448+ /// Used when a symbol has documentation spread across multiple XML doc elements.
421449 let combineComments ( c1 : ApiDocComment ) ( c2 : ApiDocComment ) =
422450 ApiDocComment(
423451 xmldoc =
@@ -434,19 +462,28 @@ module internal XmlDocReader =
434462 rawData = c1.RawData @ c2.RawData
435463 )
436464
465+ /// Reduces a list of optional <see cref =" T:FSharp.Formatting.ApiDocs.ApiDocComment " /> values
466+ /// (namespace-level doc fragments) by combining all non-<c >None</c > entries into one.
467+ /// Returns <c >None</c > when the list is empty or all entries are <c >None</c >.
437468 let combineNamespaceDocs nspDocs =
438469 nspDocs
439470 |> List.choose id
440471 |> function
441472 | [] -> None
442473 | xs -> Some( List.reduce combineComments xs)
443474
475+ /// Top-level XML doc reader: parses a <c >< ; member> ; </c > element (or similar) into an
476+ /// <see cref =" T:FSharp.Formatting.ApiDocs.ApiDocComment " /> and a separate namespace-doc
477+ /// comment extracted from any embedded <c >< ; namespacedoc> ; </c > elements.
444478 let rec readXmlCommentAsHtml ( urlMap : CrossReferenceResolver ) ( doc : XElement ) ( cmds : IDictionary < _ , _ >) =
445479 let doc , nsels = readXmlCommentAsHtmlAux true urlMap doc cmds
446480
447481 let nsdocs = readNamespaceDocs urlMap nsels
448482 doc, nsdocs
449483
484+ /// Reads the contents of <c >< ; namespacedoc> ; </c > elements into a combined namespace
485+ /// <see cref =" T:FSharp.Formatting.ApiDocs.ApiDocComment " />, or returns <c >None</c > when
486+ /// the list is empty.
450487 and readNamespaceDocs ( urlMap : CrossReferenceResolver ) ( nsels : XElement list option ) =
451488 let nscmds = Dictionary() :> IDictionary<_, _>
452489
0 commit comments