Skip to content

Commit 7225dd9

Browse files
committed
Include Mentioned In links in the HTML content
1 parent 4c60f0c commit 7225dd9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Sources/SwiftDocC/Model/Rendering/HTML/HTMLRenderer.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,21 @@ struct HTMLRenderer {
445445
articleElement.addChild(.element(named: "hr")) // Separate the sections with a thematic break
446446
}
447447

448+
if FeatureFlags.current.isMentionedInEnabled {
449+
separateCurationIfNeeded()
450+
451+
let mentions = context.articleSymbolMentions.articlesMentioning(reference)
452+
if !mentions.isEmpty {
453+
articleElement.addChild(
454+
renderer.selfReferencingSection(named: "Mentioned In", content: [
455+
.element(named: "ul", children: mentions.compactMap { reference in
456+
context.documentationCache[reference].map { .element(named: "li", children: [.text($0.name.description)]) }
457+
})
458+
])
459+
)
460+
}
461+
}
462+
448463
// Discussion
449464
if let discussion = symbol.discussion {
450465
separateCurationIfNeeded()

Tests/SwiftDocCUtilitiesTests/FileWritingHTMLContentConsumerTests.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class FileWritingHTMLContentConsumerTests: XCTestCase {
2727
2828
## Custom discussion
2929
30-
It explains how a developer can perform some task using this module.
30+
It explains how a developer can perform some task using ``SomeClass`` in this module.
3131
3232
### Details
3333
@@ -254,6 +254,12 @@ final class FileWritingHTMLContentConsumerTests: XCTestCase {
254254
<code>class SomeClass</code>
255255
</pre>
256256
</section>
257+
<section>
258+
<h2>Mentioned In</h2>
259+
<ul>
260+
<li>Some article</li>
261+
</ul>
262+
</section>
257263
<section>
258264
<h2>Topics</h2>
259265
<h3>Instance Methods</h3>
@@ -369,7 +375,10 @@ final class FileWritingHTMLContentConsumerTests: XCTestCase {
369375
</section>
370376
<section>
371377
<h2>Custom discussion</h2>
372-
<p>It explains how a developer can perform some task using this module.</p>
378+
<p>It explains how a developer can perform some task using <a href="../SomeClass/index.html">
379+
<code>SomeClass</code>
380+
</a>
381+
in this module.</p>
373382
<h3>Details</h3>
374383
<p>This subsection describes something more detailed.</p>
375384
</section>

0 commit comments

Comments
 (0)