Skip to content

Commit a89cd8f

Browse files
committed
Fix custom doc link title issue
1 parent a3c31ee commit a89cd8f

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolutionMigration.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ enum LinkResolutionMigrationConfiguration {
2121

2222
/// Whether or not the context should the a ``PathHierarchyBasedLinkResolver`` to resolve links.
2323
static var shouldUseHierarchyBasedLinkResolver: Bool = {
24-
return UserDefaults.standard.bool(forKey: "DocCUseHierarchyBasedLinkResolver")
25-
|| ProcessInfo.processInfo.environment["DOCC_USE_HIERARCHY_BASED_LINK_RESOLVER"] == "YES"
24+
return true
25+
// return UserDefaults.standard.bool(forKey: "DocCUseHierarchyBasedLinkResolver")
26+
// || ProcessInfo.processInfo.environment["DOCC_USE_HIERARCHY_BASED_LINK_RESOLVER"] == "YES"
2627
}()
2728

2829
/// Whether or not the context should report differences between the disambiguated paths created by ``PathHierarchyBasedLinkResolver`` and ``DocumentationCacheBasedLinkResolver``.
@@ -31,8 +32,9 @@ enum LinkResolutionMigrationConfiguration {
3132
/// - When the cache based resolved is used to resolve links both mismatched symbol paths and mismatched link resolution reports will be reported.
3233
/// - When the path hierarchy based resolved is used to resolve links only mismatched symbol paths will be reported.
3334
static var shouldReportLinkResolutionMismatches: Bool = {
34-
return UserDefaults.standard.bool(forKey: "DocCReportLinkResolutionMismatches")
35-
|| ProcessInfo.processInfo.environment["DOCC_REPORT_LINK_RESOLUTION_MISMATCHES"] == "YES"
35+
return true
36+
// return UserDefaults.standard.bool(forKey: "DocCReportLinkResolutionMismatches")
37+
// || ProcessInfo.processInfo.environment["DOCC_REPORT_LINK_RESOLUTION_MISMATCHES"] == "YES"
3638
}()
3739

3840
// MARK: Derived conditions

Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,22 @@ struct RenderContentCompiler: MarkupVisitor {
163163
return [RenderInlineContent.text(link.plainText)]
164164
}
165165

166-
return [RenderInlineContent.reference(identifier: .init(resolved.absoluteString), isActive: true, overridingTitle: nil, overridingTitleInlineContent: nil)]
166+
let linkTitleInlineContent = link.children.flatMap { visit($0) } as! [RenderInlineContent]
167+
let plainTextLinkTitle = linkTitleInlineContent.plainText
168+
169+
var overridingTitle = plainTextLinkTitle.isEmpty ? nil : plainTextLinkTitle
170+
var overridingTitleInlineContent = linkTitleInlineContent.isEmpty ? nil : linkTitleInlineContent
171+
// Check if the link is `<>` form
172+
if let linkRange = link.range,
173+
let childRange = link.firstChildRange() {
174+
let lowerBound = SourceLocation(line: childRange.lowerBound.line, column: childRange.lowerBound.column - 1, source: childRange.lowerBound.source)
175+
let upperBound = SourceLocation(line: childRange.upperBound.line, column: childRange.upperBound.column + 1, source: childRange.upperBound.source)
176+
if linkRange == lowerBound ..< upperBound {
177+
overridingTitle = nil
178+
overridingTitleInlineContent = nil
179+
}
180+
}
181+
return [RenderInlineContent.reference(identifier: .init(resolved.absoluteString), isActive: true, overridingTitle: overridingTitle, overridingTitleInlineContent: overridingTitleInlineContent)]
167182
}
168183

169184
mutating func resolveTopicReference(_ destination: String) -> ResolvedTopicReference? {

Sources/SwiftDocC/Semantics/MarkupReferenceResolver.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,13 @@ struct MarkupReferenceResolver: MarkupRewriter {
113113
guard let resolvedURL = resolve(reference: unresolved, range: link.range, severity: .warning) else {
114114
return link
115115
}
116-
var link = link
117-
link.destination = resolvedURL.absoluteString
118-
return link
116+
if link.destination != resolvedURL.absoluteString {
117+
var link = link
118+
link.destination = resolvedURL.absoluteString
119+
return link
120+
} else {
121+
return link
122+
}
119123
}
120124

121125
mutating func resolveAbsoluteSymbolLink(unresolvedDestination: String, elementRange range: SourceRange?) -> ResolvedTopicReference? {

0 commit comments

Comments
 (0)