Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit adf589c

Browse files
Fixing protocol requirements html rendering
1 parent bac2610 commit adf589c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Sources/swift-doc/Supporting Types/Components/Requirements.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ struct Requirements: Component {
1313
self.module = module
1414
}
1515

16+
var sections: [(title: String, requirements: [Symbol])] {
17+
return [
18+
("Requirements", module.interface.requirements(of: symbol)),
19+
("Optional Requirements", module.interface.optionalRequirements(of: symbol))
20+
].filter { !$0.requirements.isEmpty }
21+
}
22+
1623
// MARK: - Component
1724

1825
var fragment: Fragment {
19-
let sections: [(title: String, requirements: [Symbol])] = [
20-
("Requirements", module.interface.requirements(of: symbol)),
21-
("Optional Requirements", module.interface.optionalRequirements(of: symbol))
22-
].filter { !$0.requirements.isEmpty}
2326
guard !sections.isEmpty else { return Fragment { "" } }
2427

2528
return Fragment {
@@ -37,7 +40,26 @@ struct Requirements: Component {
3740

3841
var html: HypertextLiteral.HTML {
3942
return #"""
43+
\#(sections.map { section -> HypertextLiteral.HTML in
44+
#"""
45+
<section id=\#(section.title.lowercased())>
46+
<h2>\#(section.title)</h2>
47+
48+
\#(section.requirements.map { member -> HypertextLiteral.HTML in
49+
let descriptor = String(describing: type(of: symbol.api)).lowercased()
4050

51+
return #"""
52+
<div role="article" class="\#(descriptor)" id=\#(member.id.description.lowercased().replacingOccurrences(of: " ", with: "-"))>
53+
<h3>
54+
<code>\#(softbreak(member.name))</code>
55+
</h3>
56+
\#(Documentation(for: member, in: module).html)
57+
</div>
58+
"""#
59+
})
60+
</section>
61+
"""#
62+
})
4163
"""#
4264
}
4365
}

0 commit comments

Comments
 (0)