diff --git a/Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy.swift b/Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy.swift index f6842763f3..87d5ac8fcf 100644 --- a/Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy.swift +++ b/Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy.swift @@ -764,10 +764,16 @@ extension PathHierarchy { let isAbsolute = path.first == "/" || String(components.first ?? "") == NodeURLGenerator.Path.documentationFolderName || String(components.first ?? "") == NodeURLGenerator.Path.tutorialsFolderName - + + // If there is a # character in the last component, split that into two components if let hashIndex = components.last?.firstIndex(of: "#") { let last = components.removeLast() - components.append(last[.. + - + + """.write(to: url.appendingPathComponent("ArticleWithHeading.md"), atomically: true, encoding: .utf8) + } + + let tree = try XCTUnwrap(context.hierarchyBasedLinkResolver?.pathHierarchy) + let articleNode = try tree.findNode(path: "/MixedLanguageFramework/ArticleWithHeading", onlyFindSymbols: false) + + let linkNode = try tree.find(path: "TestTargetHeading", parent: articleNode.identifier, onlyFindSymbols: false) + let anchorLinkNode = try tree.find(path: "#TestTargetHeading", parent: articleNode.identifier, onlyFindSymbols: false) + XCTAssertNotNil(linkNode) + XCTAssertNotNil(anchorLinkNode) + } + func testOverloadedSymbols() throws { try XCTSkipUnless(LinkResolutionMigrationConfiguration.shouldUseHierarchyBasedLinkResolver) let (_, context) = try testBundleAndContext(named: "OverloadedSymbols") @@ -1555,6 +1579,7 @@ class PathHierarchyTests: XCTestCase { assertParsedPathComponents("first/", [("first", nil, nil)]) assertParsedPathComponents("first//second", [("first", nil, nil), ("second", nil, nil)]) assertParsedPathComponents("first/second#third", [("first", nil, nil), ("second", nil, nil), ("third", nil, nil)]) + assertParsedPathComponents("#first", [("first", nil, nil)]) // Check disambiguation assertParsedPathComponents("path-hash", [("path", nil, "hash")])