Skip to content

Commit b9d9ada

Browse files
Support authoring a single anonymous topics section (#421)
The initial implementation of anonymous topics sections didn’t account for the use-case of a single, anonymous topic section. The current markup parsing logic expects to find at least one H3 heading inside a valid topic section. So while the rest of DocC’s navigator logic was ready to handle this markup, the initial check for the existence and range of the task group in the markup failed to return a value for this use case. Resolves rdar://100994549
1 parent 6e35675 commit b9d9ada

File tree

5 files changed

+49
-157
lines changed

5 files changed

+49
-157
lines changed

Sources/SwiftDocC/Checker/Checkers/TopicsSectionWithoutSubheading.swift

Lines changed: 0 additions & 52 deletions
This file was deleted.

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
400400
MissingAbstract(sourceFile: source).any(),
401401
NonOverviewHeadingChecker(sourceFile: source).any(),
402402
SeeAlsoInTopicsHeadingChecker(sourceFile: source).any(),
403-
TopicsSectionWithoutSubheading(sourceFile: source).any(),
404403
])
405404
checker.visit(document)
406405
diagnosticEngine.emit(checker.problems)

Sources/SwiftDocC/Model/DocumentationMarkup.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ struct DocumentationMarkup {
247247
topicsFirstTaskGroupIndex = index
248248
}
249249
}
250+
// The first topic group in a topic section is allowed to be "anonymous", or without
251+
// an H3 heading. We account for this by treating both UnorderedLists and Paragraphs as
252+
// valid children indicating the start of a task group.
253+
else if child is UnorderedList {
254+
topicsFirstTaskGroupIndex = index
255+
} else if child is Paragraph {
256+
topicsFirstTaskGroupIndex = index
257+
}
250258

251259
if topicsIndex == nil { topicsIndex = index }
252260

Tests/SwiftDocCTests/Checker/Checkers/TopicsSectionWithoutSubheadingTests.swift

Lines changed: 0 additions & 104 deletions
This file was deleted.

Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,4 +3174,45 @@ Document
31743174
]
31753175
)
31763176
}
3177+
3178+
func testTopicsSectionWithSingleAnonymousTopicGroup() throws {
3179+
let (_, bundle, context) = try testBundleAndContext(
3180+
copying: "TestBundle",
3181+
configureBundle: { url in
3182+
try """
3183+
# Article
3184+
3185+
Abstract.
3186+
3187+
## Topics
3188+
3189+
- ``MyKit/MyProtocol``
3190+
- ``MyKit/MyClass``
3191+
3192+
""".write(to: url.appendingPathComponent("article.md"), atomically: true, encoding: .utf8)
3193+
}
3194+
)
3195+
3196+
let articleReference = ResolvedTopicReference(
3197+
bundleIdentifier: bundle.identifier,
3198+
path: "/documentation/Test-Bundle/article",
3199+
sourceLanguage: .swift
3200+
)
3201+
3202+
let articleNode = try context.entity(with: articleReference)
3203+
3204+
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleNode.reference, source: nil)
3205+
let articleRenderNode = try XCTUnwrap(translator.visit(articleNode.semantic) as? RenderNode)
3206+
3207+
XCTAssertEqual(
3208+
articleRenderNode.topicSections.flatMap { taskGroup in
3209+
[taskGroup.title] + taskGroup.identifiers
3210+
},
3211+
[
3212+
nil,
3213+
"doc://org.swift.docc.example/documentation/MyKit/MyProtocol",
3214+
"doc://org.swift.docc.example/documentation/MyKit/MyClass",
3215+
]
3216+
)
3217+
}
31773218
}

0 commit comments

Comments
 (0)