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

Commit

Permalink
Update CommonMark dependency to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Jan 24, 2020
1 parent 253532b commit 9f4e0f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/SwiftDocOrg/CommonMark.git",
"state": {
"branch": null,
"revision": "2f5a2a42c804bdfcc3791d6ca75874b121bd91c3",
"version": "0.1.2"
"revision": "9367f90bffdb0ac66f855c979eb87711b906817d",
"version": "0.2.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/SwiftDocOrg/CommonMark.git", from: "0.1.2"),
.package(url: "https://github.com/SwiftDocOrg/CommonMark.git", .upToNextMinor(from: "0.2.0")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
18 changes: 8 additions & 10 deletions Sources/SwiftMarkup/Documentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,40 +224,38 @@ extension Documentation {

func visitDocument(_ node: Document) {
assert(state == .initial)
guard let firstChild = node.children.first,
firstChild is Block
else {
return
guard let firstChild = node.children.first else {
return
}

state = firstChild is Paragraph ? .summary : .discussion

for case let child as Block in node.children {
for case let child in node.children {
visitBlock(child)
}
}

private func visitBlock(_ node: Block) {
private func visitBlock(_ node: Node & Block) {
switch (state, node) {
case (.summary, _):
documentation.summary = node.description.trimmingCharacters(in: .whitespacesAndNewlines)
state = .discussion
case (.discussion, let list as BulletList):
case (.discussion, let list as List) where list.kind == .bullet:
visitBulletList(list)
default:
documentation.discussionParts += [node.description]
}
}

private func visitBulletList(_ node: BulletList) {
private func visitBulletList(_ node: List) {
for item in node.children {
visitBulletListItem(item)
}

state = .discussion
}

private func visitBulletListItem(_ node: ListItem) {
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])
Expand Down Expand Up @@ -289,7 +287,7 @@ extension Documentation {
case .discussion:
if name.caseInsensitiveCompare("parameters") == .orderedSame {
state = .parameters
for case let nestedBulletList as BulletList in node.children {
for case let nestedBulletList as List in node.children where nestedBulletList.kind == .bullet {
visitBulletList(nestedBulletList)
}
} else if name.caseInsensitiveCompare("parameter") == .orderedSame {
Expand Down

0 comments on commit 9f4e0f4

Please sign in to comment.