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

Commit 45aa273

Browse files
authored
Merge branch 'compnerd/semantics' into compnerd/windows-ci
2 parents 13ed8f1 + 76679a3 commit 45aa273

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ let package = Package(
1313
.library(name: "SwiftDoc", targets: ["SwiftDoc"])
1414
],
1515
dependencies: [
16-
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .revision("4ae758ab85ed2a5d3e3e8b5050a8ce52179bd102")),
17-
.package(url: "https://github.com/SwiftDocOrg/SwiftSemantics.git", .revision("0.3.1")),
16+
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .revision("release/5.5")),
17+
.package(url: "https://github.com/SwiftDocOrg/SwiftSemantics.git", .upToNextMinor(from: "0.3.2")),
1818
.package(url: "https://github.com/SwiftDocOrg/CommonMark.git", .upToNextMinor(from: "0.5.1")),
1919
.package(url: "https://github.com/SwiftDocOrg/SwiftMarkup.git", .upToNextMinor(from: "0.3.0")),
2020
.package(url: "https://github.com/SwiftDocOrg/GraphViz.git", .upToNextMinor(from: "0.4.1")),

Sources/SwiftDoc/Helpers.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ public func path(for symbol: Symbol, with baseURL: String) -> String {
1414
}
1515

1616
public func path(for identifier: CustomStringConvertible, with baseURL: String) -> String {
17-
let url = URL(string: baseURL)?.appendingPathComponent("\(identifier)") ?? URL(string: "\(identifier)")
17+
let tail: String = path(for: "\(identifier)")
18+
let url = URL(string: baseURL)?.appendingPathComponent(tail) ?? URL(string: tail)
1819
guard let string = url?.absoluteString else {
1920
fatalError("Unable to construct path for \(identifier) with baseURL \(baseURL)")
2021
}
2122

2223
return string
2324
}
25+
26+
private let reservedCharacters: CharacterSet = [
27+
// Windows Reserved Characters
28+
"<", ">", ":", "\"", "/", "\\", "|", "?", "*",
29+
]
30+
31+
public func path(for identifier: String) -> String {
32+
return identifier.components(separatedBy: reservedCharacters).joined(separator: "_")
33+
}

Sources/swift-doc/Subcommands/Generate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ extension SwiftDoc {
134134
let filename: String
135135
switch format {
136136
case .commonmark:
137-
filename = "\($0.key).md"
137+
filename = "\(path(for: $0.key)).md"
138138
case .html where $0.key == "Home":
139139
filename = "index.html"
140140
case .html:
141-
filename = "\($0.key)/index.html"
141+
filename = "\(path(for: $0.key))/index.html"
142142
}
143143

144144
let url = outputDirectoryURL.appendingPathComponent(filename)

Tests/SwiftDocTests/PathTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@ final class PathTests: XCTestCase {
66
func testEmptyBaseURL() {
77
XCTAssertEqual(path(for: "Class", with: ""), "Class")
88

9-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: ""), "(lhs:rhs:)")
9+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: ""), "(lhs_rhs_)")
1010
}
1111

1212
func testRootDirectoryBaseURL() {
1313
XCTAssertEqual(path(for: "Class", with: "/"), "/Class")
1414

15-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "/"), "/(lhs:rhs:)")
15+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "/"), "/(lhs_rhs_)")
1616
}
1717

1818
func testCurrentDirectoryBaseURL() {
1919
XCTAssertEqual(path(for: "Class", with: "./"), "./Class")
2020

21-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "./"), "./(lhs:rhs:)")
21+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "./"), "./(lhs_rhs_)")
2222
}
2323

2424
func testNestedSubdirectoryBaseURL() {
2525
XCTAssertEqual(path(for: "Class", with: "/path/to/directory"), "/path/to/directory/Class")
2626
XCTAssertEqual(path(for: "Class", with: "/path/to/directory/"), "/path/to/directory/Class")
2727

28-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "/path/to/directory"), "/path/to/directory/(lhs:rhs:)")
29-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "/path/to/directory/"), "/path/to/directory/(lhs:rhs:)")
28+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "/path/to/directory"), "/path/to/directory/(lhs_rhs_)")
29+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "/path/to/directory/"), "/path/to/directory/(lhs_rhs_)")
3030
}
3131

3232
func testDomainBaseURL() {
3333
XCTAssertEqual(path(for: "Class", with: "https://example.com"), "https://example.com/Class")
3434
XCTAssertEqual(path(for: "Class", with: "https://example.com/"), "https://example.com/Class")
3535

36-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "https://example.com"), "https://example.com/(lhs:rhs:)")
37-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "https://example.com/"), "https://example.com/(lhs:rhs:)")
36+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "https://example.com"), "https://example.com/(lhs_rhs_)")
37+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "https://example.com/"), "https://example.com/(lhs_rhs_)")
3838
}
3939

4040
func testDomainSubdirectoryBaseURL() {
4141
XCTAssertEqual(path(for: "Class", with: "https://example.com/docs"), "https://example.com/docs/Class")
4242
XCTAssertEqual(path(for: "Class", with: "https://example.com/docs/"), "https://example.com/docs/Class")
4343

44-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "https://example.com/docs"), "https://example.com/docs/(lhs:rhs:)")
45-
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "https://example.com/docs/"), "https://example.com/docs/(lhs:rhs:)")
44+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "https://example.com/docs"), "https://example.com/docs/(lhs_rhs_)")
45+
XCTAssertEqual(path(for: "(lhs:rhs:)", with: "https://example.com/docs/"), "https://example.com/docs/(lhs_rhs_)")
4646
}
4747
}

0 commit comments

Comments
 (0)