@@ -168,7 +168,7 @@ private struct ParametersDocumentationExtractor {
168
168
169
169
let remainingContent = String ( paragraphContent [ prefixEnd... ] ) . trimmingCharacters ( in: . whitespaces)
170
170
171
- return extractParam ( firstTextContent: remainingContent, listItem: listItem)
171
+ return extractParam ( firstTextContent: remainingContent, listItem: listItem, single : true )
172
172
}
173
173
174
174
/// Extracts a parameter field from a list item (used for parameter outline items)
@@ -177,23 +177,23 @@ private struct ParametersDocumentationExtractor {
177
177
return nil
178
178
}
179
179
180
- guard let paragraphText = paragraph. child ( at: 0 ) as? Text else {
181
- return nil
182
- }
180
+ let firstText = paragraph. child ( at: 0 ) as? Text
183
181
184
- return extractParam ( firstTextContent: paragraphText . string, listItem: listItem)
182
+ return extractParam ( firstTextContent: firstText ? . string ?? " " , listItem: listItem, single : false )
185
183
}
186
184
187
185
/// Extracts a parameter field from a list item provided the relevant first text content allowing reuse in ``extractOutlineItem`` and ``extractSingle``
188
186
///
189
187
/// - Parameters:
190
188
/// - firstTextContent: The content of the first text child of the list item's first paragraph
191
189
/// - listItem: The list item to extract the parameter from
190
+ /// - single: Whether the parameter is a single parameter or part of a parameter outline
192
191
///
193
192
/// - Returns: A tuple containing the parameter name and documentation if a parameter was found, nil otherwise.
194
193
private func extractParam(
195
194
firstTextContent: String ,
196
- listItem: ListItem
195
+ listItem: ListItem ,
196
+ single: Bool
197
197
) -> Parameter ? {
198
198
guard let paragraph = listItem. child ( at: 0 ) as? Paragraph else {
199
199
return nil
@@ -202,7 +202,7 @@ private struct ParametersDocumentationExtractor {
202
202
let components = firstTextContent. split ( separator: " : " , maxSplits: 1 , omittingEmptySubsequences: false )
203
203
204
204
guard components. count == 2 else {
205
- return nil
205
+ return extractWithRawIdentifier ( from : listItem , single : single )
206
206
}
207
207
208
208
let name = String ( components [ 0 ] ) . trimmingCharacters ( in: . whitespaces)
@@ -217,6 +217,44 @@ private struct ParametersDocumentationExtractor {
217
217
218
218
return Parameter ( name: name, documentation: documentation)
219
219
}
220
+
221
+ /// Extracts a parameter with its name as a raw identifier.
222
+ ///
223
+ /// Example:
224
+ /// ```markdown
225
+ /// - Parameter `foo bar`: documentation
226
+ /// - Parameters:
227
+ /// - `foo bar`: documentation
228
+ /// ```
229
+ ///
230
+ /// - Parameters:
231
+ /// - listItem: The list item to extract the parameter from
232
+ /// - single: Whether the parameter is a single parameter or part of a parameter outline
233
+ func extractWithRawIdentifier( from listItem: ListItem , single: Bool ) -> Parameter ? {
234
+ /// The index of ``InlineCode`` for the raw identifier parameter name in the first paragraph of ``listItem``
235
+ let inlineCodeIndex = single ? 1 : 0
236
+
237
+ guard let paragraph = listItem. child ( at: 0 ) as? Paragraph ,
238
+ let rawIdentifier = paragraph. child ( at: inlineCodeIndex) as? InlineCode ,
239
+ let text = paragraph. child ( at: inlineCodeIndex + 1 ) as? Text
240
+ else {
241
+ return nil
242
+ }
243
+
244
+ let textContent = text. string. trimmingCharacters ( in: . whitespaces)
245
+
246
+ guard textContent. hasPrefix ( " : " ) else {
247
+ return nil
248
+ }
249
+
250
+ let remainingTextContent = String ( textContent. dropFirst ( ) ) . trimmingCharacters ( in: . whitespaces)
251
+ let remainingParagraphChildren =
252
+ [ Text ( remainingTextContent) ] + paragraph. inlineChildren. dropFirst ( inlineCodeIndex + 2 )
253
+ let remainingChildren = [ Paragraph ( remainingParagraphChildren) ] + listItem. blockChildren. dropFirst ( 1 )
254
+ let documentation = Document ( remainingChildren) . format ( )
255
+
256
+ return Parameter ( name: rawIdentifier. code, documentation: documentation)
257
+ }
220
258
}
221
259
222
260
/// Extracts parameter documentation from markdown text.
0 commit comments