Skip to content

Commit d56e5a9

Browse files
authored
Fix article abstract section issue (#347)
* Fix article abstract section issue * Add @comment test for abstract
1 parent a4021f1 commit d56e5a9

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Sources/SwiftDocC/Model/DocumentationMarkup.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Markdown
2222
/// # My Document
2323
/// ```
2424
/// ### Abstract
25-
/// The parser parses the abstract from the first leading paragraph in the markup after the title. If the markup doesn't start with a paragraph after the title heading, it's considered to not have an abstract.
25+
/// The parser parses the abstract from the first leading paragraph (skipping the comments) in the markup after the title. If the markup doesn't start with a paragraph after the title heading, it's considered to not have an abstract.
2626
/// ```
2727
/// # My Document
2828
/// An abstract shortly describing My Document.
@@ -146,6 +146,10 @@ struct DocumentationMarkup {
146146
if directive.name == DeprecationSummary.directiveName {
147147
deprecation = MarkupContainer(directive.children)
148148
}
149+
// Skip other block like @Comment and so on.
150+
return
151+
} else if let _ = child as? HTMLBlock {
152+
// Skip HTMLBlock comment.
149153
return
150154
} else {
151155
// Only directives and a single paragraph allowed in an abstract,

Sources/SwiftDocC/Semantics/Article/Article.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class Article: Semantic, MarkupConvertible, Abstracted, Redirected,
3131
/// - metadata: An optional container for metadata that's unrelated to the article's content.
3232
/// - redirects: An optional list of previously known locations for this article.
3333
init(markup: Markup?, metadata: Metadata?, redirects: [Redirect]?) {
34-
let markupModel = markup.map({ DocumentationMarkup(markup: $0) })
34+
let markupModel = markup.map { DocumentationMarkup(markup: $0) }
3535

3636
self.markup = markup
3737
self.metadata = metadata

Tests/SwiftDocCTests/Model/DocumentationMarkupTests.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -158,6 +158,24 @@ class DocumentationMarkupTests: XCTestCase {
158158
XCTAssertEqual(expected, model.abstractSection?.content.map({ $0.detachedFromParent.debugDescription() }).joined(separator: "\n"))
159159
}
160160

161+
// Contains an HTMLBlock comment and a BlockDirective comment before the abstract
162+
do {
163+
let source = """
164+
# Title
165+
<!--Line a-->
166+
@Comment{
167+
Line b
168+
}
169+
Line c
170+
## Hello, world!
171+
Discussion content.
172+
"""
173+
let expected = """
174+
Text \"Line c\"
175+
"""
176+
let model = DocumentationMarkup(markup: Document(parsing: source, options: .parseBlockDirectives))
177+
XCTAssertEqual(expected, model.abstractSection?.content.map{ $0.detachedFromParent.debugDescription() }.joined(separator: "\n"))
178+
}
161179
}
162180

163181
func testDeprecation() throws {

0 commit comments

Comments
 (0)