` HTML element that represents a symbol's subheading.
+ ///
+ /// When the renderer has a ``RenderGoal/richness`` goal, it creates one `` HTML element per fragment that could be styled differently through CSS:
+ /// ```
+ ///
+ /// class
+ /// Some Class
+ ///
+ /// ```
+ ///
+ /// When the renderer has a ``RenderGoal/conciseness`` goal, it joins the fragment's text into a single string:
+ /// ```
+ /// class SomeClass
+ /// ```
+ private func _symbolSubheading(_ fragments: [LinkedElement.SymbolNameFragment], languageFilter: SourceLanguage?) -> XMLElement {
+ switch goal {
+ case .richness:
+ .element(
+ named: "code",
+ children: fragments.map {
+ .element(named: "span", children: wordBreak(symbolName: $0.text), attributes: ["class": $0.kind.rawValue])
+ },
+ attributes: languageFilter.map { ["class": "\($0.id)-only"] }
+ )
+ case .conciseness:
+ .element(
+ named: "code",
+ children: [.text(fragments.map(\.text).joined())],
+ attributes: languageFilter.map { ["class": "\($0.id)-only"] }
+ )
+ }
+ }
+}
diff --git a/Tests/DocCHTMLTests/MarkdownRenderer+PageElementsTests.swift b/Tests/DocCHTMLTests/MarkdownRenderer+PageElementsTests.swift
index c54c7751e..199a88a9b 100644
--- a/Tests/DocCHTMLTests/MarkdownRenderer+PageElementsTests.swift
+++ b/Tests/DocCHTMLTests/MarkdownRenderer+PageElementsTests.swift
@@ -42,7 +42,7 @@ struct MarkdownRenderer_PageElementsTests {
.init(text: "Something", kind: .identifier),
],
.objectiveC: [
- .init(text: "class ", kind: .decorator),
+ .init(text: "@interface ", kind: .decorator),
.init(text: "TLASomething", kind: .identifier),
],
]),
@@ -482,6 +482,165 @@ struct MarkdownRenderer_PageElementsTests {
}
}
+ @Test(arguments: RenderGoal.allCases, ["Topics", "See Also"])
+ func testRenderSingleLanguageGroupedSectionsWithMultiLanguageLinks(goal: RenderGoal, expectedGroupTitle: String) {
+ let elements = [
+ LinkedElement(
+ path: URL(string: "/documentation/ModuleName/SomeClass/index.html")!,
+ names: .languageSpecificSymbol([
+ .swift: "SomeClass",
+ .objectiveC: "TLASomeClass",
+ ]),
+ subheadings: .languageSpecificSymbol([
+ .swift: [
+ .init(text: "class ", kind: .decorator),
+ .init(text: "SomeClass", kind: .identifier),
+ ],
+ .objectiveC: [
+ .init(text: "@interface ", kind: .decorator),
+ .init(text: "TLASomeClass", kind: .identifier),
+ ],
+ ]),
+ abstract: parseMarkup(string: "Some _formatted_ description of this class").first as? Paragraph
+ ),
+ LinkedElement(
+ path: URL(string: "/documentation/ModuleName/SomeArticle/index.html")!,
+ names: .single(.conceptual("Some Article")),
+ subheadings: .single(.conceptual("Some Article")),
+ abstract: parseMarkup(string: "Some **formatted** description of this _article_.").first as? Paragraph
+ ),
+ LinkedElement(
+ path: URL(string: "/documentation/ModuleName/SomeClass/someMethod(with:and:)/index.html")!,
+ names: .languageSpecificSymbol([
+ .swift: "someMethod(with:and:)",
+ .objectiveC: "someMethodWithFirst:andSecond:",
+ ]),
+ subheadings: .languageSpecificSymbol([
+ .swift: [
+ .init(text: "func ", kind: .decorator),
+ .init(text: "someMethod", kind: .identifier),
+ .init(text: "(", kind: .decorator),
+ .init(text: "with", kind: .identifier),
+ .init(text: ": Int, ", kind: .decorator),
+ .init(text: "and", kind: .identifier),
+ .init(text: ": String)", kind: .decorator),
+ ],
+ .objectiveC: [
+ .init(text: "- ", kind: .decorator),
+ .init(text: "someMethodWithFirst:andSecond:", kind: .identifier),
+ ],
+ ]),
+ abstract: nil
+ ),
+ ]
+
+ let renderer = makeRenderer(goal: goal, elementsToReturn: elements)
+ let expectedSectionID = expectedGroupTitle.replacingOccurrences(of: " ", with: "-")
+ let groupedSection = renderer.groupedSection(named: expectedGroupTitle, groups: [
+ .swift: [
+ .init(title: "Group title", content: parseMarkup(string: "Some description of this group"), references: [
+ URL(string: "/documentation/ModuleName/SomeClass/index.html")!,
+ URL(string: "/documentation/ModuleName/SomeArticle/index.html")!,
+ URL(string: "/documentation/ModuleName/SomeClass/someMethod(with:and:)/index.html")!,
+ ])
+ ]
+ ])
+
+ switch goal {
+ case .richness:
+ groupedSection.assertMatches(prettyFormatted: true, expectedXMLString: """
+
+
+ \(expectedGroupTitle)
+
+
+ Group title
+
+ Some description of this group
+
+ -
+
+
+ class
+ Some
+ Class
+
+
+ @interface
+ TLASome
+ Class
+
+ Some formatted
+ description of this class
+
+
+ -
+
+
Some Article
+ Some formatted
+ description of this article
+ .
+
+
+ -
+
+
+ func
+ some
+ Method
+ (
+ with
+ :
+ Int,
+ and
+ :
+ String)
+
+
+ -
+ some
+ Method
+ With
+ First:
+ and
+ Second:
+
+
+
+
+
+ """)
+ case .conciseness:
+ groupedSection.assertMatches(prettyFormatted: true, expectedXMLString: """
+ \(expectedGroupTitle)
+ Group title
+ Some description of this group
+
+ """)
+ }
+ }
+
// MARK: -
private func makeRenderer(