Skip to content

Use a custom scheme for local "Declared In" source file URLs #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Sources/SwiftDocC/SourceRepository/SourceRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ public extension SourceRepository {

/// Creates a source repository hosted by the device's filesystem.
///
/// Use this source repository to format `file://` links to files on the
/// Use this source repository to format `doc-source-file://` links to files on the
/// device where documentation is being presented.
///
/// This source repository uses a custom scheme to offer more control local source file navigation.
static func localFilesystem() -> SourceRepository {
SourceRepository(
checkoutPath: "",
sourceServiceBaseURL: URL(fileURLWithPath: "/"),
// 2 slashes to specify an empty authority/host component and 1 slash to specify a base path at the root.
sourceServiceBaseURL: URL(string: "doc-source-file:///")!,
formatLineNumber: { line in "L\(line)" }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ConvertServiceTests: XCTestCase {

XCTAssertEqual(
renderNode.metadata.remoteSource?.url.absoluteString,
"file:///private/tmp/test.swift#L2"
"doc-source-file:///private/tmp/test.swift#L2"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SourceRepositoryTests: XCTestCase {
XCTAssertEqual(
SourceRepository.localFilesystem()
.format(sourceFileURL: URL(string: "file:///path/to/file")!, lineNumber: 5),
URL(string: "file:///path/to/file#L5")!
URL(string: "doc-source-file:///path/to/file#L5")!
)
}
}