Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Commit

Permalink
Parse single parameter items correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Mar 16, 2020
1 parent 33db1d5 commit 431f418
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions Sources/SwiftMarkup/Documentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,15 @@ extension Documentation {

private func visitBulletListItem(_ node: List.Item) {
let string = node.description
let pattern = #"\s*[\-\+\*]\s*(?<name>[\w\h]+):(\s*(?<description>.+))?"#
let regularExpression = try! NSRegularExpression(pattern: pattern, options: [.dotMatchesLineSeparators])
let pattern = #"\s*[\-\+\*]\s*(?<parameter>(?:Parameter\s+)?)(?<name>[\w\h]+):(\s*(?<description>.+))?"#
let regularExpression = try! NSRegularExpression(pattern: pattern, options: [.dotMatchesLineSeparators, .caseInsensitive])

guard let match = regularExpression.firstMatch(in: string, options: [], range: NSRange(string.startIndex ..< string.endIndex, in: string)),
let nameRange = Range(match.range(at: 1), in: string),
let descriptionRange = Range(match.range(at: 2), in: string)
else {
return
let parameterRange = Range(match.range(at: 1), in: string),
let nameRange = Range(match.range(at: 2), in: string),
let descriptionRange = Range(match.range(at: 3), in: string)
else {
return
}

func normalize<S: StringProtocol>(_ string: S) -> String {
Expand All @@ -291,7 +292,8 @@ extension Documentation {
}

switch state {
case .parameters:
case .parameters,
_ where !parameterRange.isEmpty:
documentation.parameters += [(name, description)]
case .discussion:
if name.caseInsensitiveCompare("parameters") == .orderedSame {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftMarkupTests/SwiftMarkupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ although the words were used with some degree of overlap for a time.
- Author: Mattt
- Complexity: `O(1)`
- Parameter style: The style of the bicycle
- Parameters:
- style: The style of the bicycle
- gearing: The gearing of the bicycle
- handlebar: The handlebar of the bicycle
- frameSize: The frame size of the bicycle, in centimeters
Expand Down

0 comments on commit 431f418

Please sign in to comment.