@@ -37,6 +37,7 @@ private static void GetCommentSections(this Comment comment, List<Section> secti
3737 switch ( blockCommandComment . CommandKind )
3838 {
3939 case CommentCommandKind . Brief :
40+ sections . Add ( new Section ( CommentElement . Summary ) ) ;
4041 blockCommandComment . ParagraphComment . GetCommentSections ( sections ) ;
4142 break ;
4243 case CommentCommandKind . Return :
@@ -85,14 +86,23 @@ private static void GetCommentSections(this Comment comment, List<Section> secti
8586 break ;
8687 }
8788 case DocumentationCommentKind . ParagraphComment :
88- var summaryParagraph = sections . Count == 1 ;
89- var paragraphComment = ( ParagraphComment ) comment ;
89+ {
90+ bool summaryParagraph = false ;
91+ if ( sections . Count == 0 )
92+ {
93+ sections . Add ( new Section ( CommentElement . Summary ) ) ;
94+ summaryParagraph = true ;
95+ }
96+
9097 var lastParagraphSection = sections . Last ( ) ;
98+ var paragraphComment = ( ParagraphComment ) comment ;
9199 foreach ( var inlineContentComment in paragraphComment . Content )
92100 {
93101 inlineContentComment . GetCommentSections ( sections ) ;
94102 if ( inlineContentComment . HasTrailingNewline )
95103 lastParagraphSection . NewLine ( ) ;
104+
105+ lastParagraphSection = sections . Last ( ) ;
96106 }
97107
98108 if ( ! string . IsNullOrEmpty ( lastParagraphSection . CurrentLine . ToString ( ) ) )
@@ -132,10 +142,33 @@ private static void GetCommentSections(this Comment comment, List<Section> secti
132142 }
133143 case DocumentationCommentKind . HTMLStartTagComment :
134144 {
145+ var startTag = ( HTMLStartTagComment ) comment ;
146+ var sectionType = CommentElementFromTag ( startTag . TagName ) ;
147+
148+ if ( IsInlineCommentElement ( sectionType ) )
149+ {
150+ var lastSection = sections . Last ( ) ;
151+ lastSection . CurrentLine . Append ( startTag ) ;
152+ break ;
153+ }
154+
155+ sections . Add ( new Section ( sectionType )
156+ {
157+ Attributes = startTag . Attributes . Select ( a => a . ToString ( ) ) . ToList ( )
158+ } ) ;
135159 break ;
136160 }
137161 case DocumentationCommentKind . HTMLEndTagComment :
138162 {
163+ var endTag = ( HTMLEndTagComment ) comment ;
164+ var sectionType = CommentElementFromTag ( endTag . TagName ) ;
165+
166+ if ( IsInlineCommentElement ( sectionType ) )
167+ {
168+ var lastSection = sections . Last ( ) ;
169+ lastSection . CurrentLine . Append ( endTag ) ;
170+ }
171+
139172 break ;
140173 }
141174 case DocumentationCommentKind . HTMLTagComment :
@@ -252,15 +285,71 @@ public List<string> GetLines()
252285 }
253286 }
254287
288+ private static CommentElement CommentElementFromTag ( string tag )
289+ {
290+ return tag . ToLowerInvariant ( ) switch
291+ {
292+ "c" => CommentElement . C ,
293+ "code" => CommentElement . Code ,
294+ "example" => CommentElement . Example ,
295+ "exception" => CommentElement . Exception ,
296+ "include" => CommentElement . Include ,
297+ "list" => CommentElement . List ,
298+ "para" => CommentElement . Para ,
299+ "param" => CommentElement . Param ,
300+ "paramref" => CommentElement . ParamRef ,
301+ "permission" => CommentElement . Permission ,
302+ "remarks" => CommentElement . Remarks ,
303+ "return" or "returns" => CommentElement . Returns ,
304+ "summary" => CommentElement . Summary ,
305+ "typeparam" => CommentElement . TypeParam ,
306+ "typeparamref" => CommentElement . TypeParamRef ,
307+ "value" => CommentElement . Value ,
308+ "seealso" => CommentElement . SeeAlso ,
309+ "see" => CommentElement . See ,
310+ "inheritdoc" => CommentElement . InheritDoc ,
311+ _ => CommentElement . Unknown
312+ } ;
313+ }
314+
315+ /// <summary>From https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments#d3-recommended-tags</summary>
316+ /// <remarks>Enum value is equal to sorting priority</remarks>
255317 private enum CommentElement
256318 {
257- Summary ,
258- Typeparam ,
259- Param ,
260- Returns ,
261- Exception ,
262- Remarks ,
263- Example
319+ C = 1000 , // Set text in a code-like font
320+ Code = 1001 , // Set one or more lines of source code or program output
321+ Example = 11 , // Indicate an example
322+ Exception = 8 , // Identifies the exceptions a method can throw
323+ Include = 1 , // Includes XML from an external file
324+ List = 1002 , // Create a list or table
325+ Para = 1003 , // Permit structure to be added to text
326+ Param = 5 , // Describe a parameter for a method or constructor
327+ ParamRef = 1004 , // Identify that a word is a parameter name
328+ Permission = 7 , // Document the security accessibility of a member
329+ Remarks = 9 , // Describe additional information about a type
330+ Returns = 6 , // Describe the return value of a method
331+ See = 1005 , // Specify a link
332+ SeeAlso = 10 , // Generate a See Also entry
333+ Summary = 2 , // Describe a type or a member of a type
334+ TypeParam = 4 , // Describe a type parameter for a generic type or method
335+ TypeParamRef = 1006 , // Identify that a word is a type parameter name
336+ Value = 3 , // Describe a property
337+ InheritDoc = 0 , // Inherit documentation from a base class
338+ Unknown = 9999 , // Unknown tag
264339 }
340+
341+ private static bool IsInlineCommentElement ( CommentElement element ) =>
342+ element switch
343+ {
344+ CommentElement . C => true ,
345+ CommentElement . Code => true ,
346+ CommentElement . List => true ,
347+ CommentElement . Para => true ,
348+ CommentElement . ParamRef => true ,
349+ CommentElement . See => true ,
350+ CommentElement . TypeParamRef => true ,
351+ CommentElement . Unknown => true , // Print unknown tags as inline
352+ _ => ( ( int ) element ) >= 1000
353+ } ;
265354 }
266355}
0 commit comments