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

Commit cc45688

Browse files
Lukas-Stuehrkmattt
andauthored
Expose deeplinks. (#275)
* Expose deeplinks. * Add changelog entry for #275 Co-authored-by: Mattt <[email protected]>
1 parent 4491f5b commit cc45688

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

Changelog.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Added support for generating documentation for
1313
private symbols.
14-
#266 by @Lukas-Stuehrk
15-
14+
#266 by @Lukas-Stuehrk.
15+
- Added anchor links to documentation entries for symbols.
16+
#275 by @Lukas-Stuehrk.
17+
1618
### Fixed
1719

1820
- Fixed bug that caused prefix and postfix operators to be omitted

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ struct Members: Component {
102102
103103
\#(section.members.map { member -> HypertextLiteral.HTML in
104104
let descriptor = String(describing: type(of: member.api)).lowercased()
105+
let id = member.id.description.lowercased().replacingOccurrences(of: " ", with: "-")
105106

106107
return #"""
107-
<div role="article" class="\#(descriptor)" id=\#(member.id.description.lowercased().replacingOccurrences(of: " ", with: "-"))>
108+
<div role="article" class="\#(descriptor)" id=\#(id)>
108109
<h3>
109-
<code>\#(softbreak(member.name))</code>
110+
<code><a href=\#("#\(id)")>\#(softbreak(member.name))</a></code>
110111
</h3>
111112
\#(Documentation(for: member, in: module, baseURL: baseURL).html)
112113
</div>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ struct OperatorImplementations: Component {
6969
heading = [operand.type, function.name].compactMap { $0 }.joined(separator: " ")
7070
}
7171

72+
let id = implementation.id.description.lowercased().replacingOccurrences(of: " ", with: "-")
73+
7274
return #"""
73-
<div role="article" class="function" id=\#(implementation.id.description.lowercased().replacingOccurrences(of: " ", with: "-"))>
75+
<div role="article" class="function" id=\#(id)>
7476
<h3>
75-
\#(heading)
76-
\#(unsafeUnescaped: function.genericWhereClause.map({ #"<small>\#($0.escaped)</small>"# }) ?? "")
77+
<a href=\#("#\(id)")>\#(heading)
78+
\#(unsafeUnescaped: function.genericWhereClause.map({ #"<small>\#($0.escaped)</small>"# }) ?? "")</a>
7779
</h3>
7880
\#(Documentation(for: implementation, in: module, baseURL: baseURL).html)
7981
</div>

Sources/swift-doc/Supporting Types/Pages/ExternalTypePage.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ struct ExternalTypePage: Page {
7070
\#(section.members.map { member -> HypertextLiteral.HTML in
7171
let descriptor = String(describing: type(of: member.api)).lowercased()
7272

73+
let id = member.id.description.lowercased().replacingOccurrences(of: " ", with: "-")
74+
7375
return #"""
74-
<div role="article" class="\#(descriptor)" id=\#(member.id.description.lowercased().replacingOccurrences(of: " ", with: "-"))>
76+
<div role="article" class="\#(descriptor)" id=\#(id)>
7577
<h3>
76-
<code>\#(softbreak(member.name))</code>
78+
<code><a href=\#("#\(id)")>\#(softbreak(member.name))</a></code>
7779
</h3>
7880
\#(Documentation(for: member, in: module, baseURL: baseURL).html)
7981
</div>

0 commit comments

Comments
 (0)