Skip to content

Commit 1f0cbf8

Browse files
committed
Fix directive parsing bug in articles
Articles currently don’t support having a directive as the first item of the discussion. This resolves the issue while maintaining compatibility with Metadata, Comment, and DeprecationSummary blocks.
1 parent 566a177 commit 1f0cbf8

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Sources/SwiftDocC/Model/DocumentationMarkup.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,17 @@ struct DocumentationMarkup {
142142
abstractSection = AbstractSection(paragraph: firstParagraph)
143143
return
144144
} else if let directive = child as? BlockDirective {
145-
// Found deprecation notice in the abstract.
146145
if directive.name == DeprecationSummary.directiveName {
146+
// Found deprecation notice in the abstract.
147147
deprecation = MarkupContainer(directive.children)
148+
return
149+
} else if directive.name == Comment.directiveName || directive.name == Metadata.directiveName {
150+
// These directives don't affect content so they shouldn't break us out of
151+
// the automatic abstract section.
152+
return
153+
} else {
154+
currentSection = .discussion
148155
}
149-
// Skip other block like @Comment and so on.
150-
return
151156
} else if let _ = child as? HTMLBlock {
152157
// Skip HTMLBlock comment.
153158
return

Tests/SwiftDocCTests/Model/DocumentationMarkupTests.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,17 @@ class DocumentationMarkupTests: XCTestCase {
7777
My abstract __content__.
7878
"""
7979
let expected = """
80-
Text "My abstract "
81-
Strong
82-
└─ Text "content"
83-
Text "."
80+
BlockDirective name: "Directive"
81+
└─ BlockDirective name: "NestedDirective"
82+
Paragraph
83+
├─ Text "My abstract "
84+
├─ Strong
85+
│ └─ Text "content"
86+
└─ Text "."
8487
"""
8588
let model = DocumentationMarkup(markup: Document(parsing: source, options: .parseBlockDirectives))
86-
XCTAssertEqual(expected, model.abstractSection?.content.map({ $0.detachedFromParent.debugDescription() }).joined(separator: "\n"))
89+
XCTAssertNil(model.abstractSection)
90+
XCTAssertEqual(expected, model.discussionSection?.content.map({ $0.detachedFromParent.debugDescription() }).joined(separator: "\n"))
8791
}
8892

8993
// Directives in between sections

0 commit comments

Comments
 (0)