@@ -75,6 +75,13 @@ public struct DocumentationComment {
75
75
/// `Throws:` prefix removed for convenience.
76
76
public var `throws` : Paragraph ? = nil
77
77
78
+ /// A collection of _all_ body nodes at the top level of the comment text.
79
+ ///
80
+ /// If a brief summary paragraph was extracted from the comment, it will not be present in this
81
+ /// collection. Any special fields extracted (parameters, returns, and throws) from `bodyNodes`
82
+ /// will be present in this collection.
83
+ internal var allBodyNodes : [ Markup ] = [ ]
84
+
78
85
/// Creates a new `DocumentationComment` with information extracted from the leading trivia of the
79
86
/// given syntax node.
80
87
///
@@ -107,6 +114,9 @@ public struct DocumentationComment {
107
114
remainingChildren = markup. children. dropFirst ( 0 )
108
115
}
109
116
117
+ // Capture all the body nodes before filtering out any special fields.
118
+ allBodyNodes = remainingChildren. map { $0. detachedFromParent }
119
+
110
120
for child in remainingChildren {
111
121
if var list = child. detachedFromParent as? UnorderedList {
112
122
// An unordered list could be one of the following:
@@ -141,24 +151,6 @@ public struct DocumentationComment {
141
151
}
142
152
}
143
153
144
- /// Creates a new `DocumentationComment` from the given `Markup` node, treated as
145
- /// the documentation for a parameter.
146
- ///
147
- /// Within the `parameterMarkup` node, only the brief summary is treated separately.
148
- /// All other nodes are treated as body nodes, without special treatment for parameters
149
- /// or return/throws documentation.
150
- private init ( parameterMarkup markup: Markup ) {
151
- // Extract the first paragraph as the brief summary. It will *not* be included in the body
152
- // nodes.
153
- if let firstParagraph = markup. child ( through: [ ( 0 , Paragraph . self) ] ) {
154
- briefSummary = firstParagraph. detachedFromParent as? Paragraph
155
- bodyNodes = markup. children. dropFirst ( ) . map { $0. detachedFromParent }
156
- } else {
157
- briefSummary = nil
158
- bodyNodes = markup. children. map { $0. detachedFromParent }
159
- }
160
- }
161
-
162
154
/// Extracts parameter fields in an outlined parameters list (i.e., `- Parameters:` containing a
163
155
/// nested list of parameter fields) from the given unordered list.
164
156
///
@@ -245,7 +237,7 @@ public struct DocumentationComment {
245
237
let name = rewriter. parameterName
246
238
else { return nil }
247
239
248
- return Parameter ( name: name, comment: DocumentationComment ( parameterMarkup : newListItem) )
240
+ return Parameter ( name: name, comment: DocumentationComment ( markup : newListItem) )
249
241
}
250
242
251
243
/// Extracts simple fields like `- Returns:` and `- Throws:` from the top-level list in the
@@ -494,7 +486,7 @@ extension DocumentationComment.Parameter {
494
486
let label = asSingle ? " Parameter \( name) : " : " \( name) : "
495
487
let summaryWithLabel = summary. prefixed ( with: label)
496
488
return ListItem (
497
- [ summaryWithLabel] + comment. bodyNodes . map { $0 as! BlockMarkup }
489
+ [ summaryWithLabel] + comment. allBodyNodes . map { $0 as! BlockMarkup }
498
490
)
499
491
}
500
492
}
0 commit comments