Skip to content

Commit 4740cae

Browse files
author
Jesse Haigh
committed
remaining PR feedback
1 parent 155ef45 commit 4740cae

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

Sources/SwiftDocC/Checker/Checkers/InvalidCodeBlockOption.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
public import Foundation
12-
public import Markdown
11+
internal import Foundation
12+
internal import Markdown
1313

1414
/**
1515
Code blocks can have a `nocopy` option after the \`\`\`, in the language line.
1616
`nocopy` can be immediately after the \`\`\` or after a specified language and a comma (`,`).
1717
*/
18-
public struct InvalidCodeBlockOption: Checker {
19-
public var problems = [Problem]()
18+
internal struct InvalidCodeBlockOption: Checker {
19+
var problems = [Problem]()
2020

2121
/// Parsing options for code blocks
2222
private let knownOptions = RenderBlockContent.CodeListing.knownOptions
@@ -26,11 +26,11 @@ public struct InvalidCodeBlockOption: Checker {
2626
/// Creates a new checker that detects documents with multiple titles.
2727
///
2828
/// - Parameter sourceFile: The URL to the documentation file that the checker checks.
29-
public init(sourceFile: URL?) {
29+
init(sourceFile: URL?) {
3030
self.sourceFile = sourceFile
3131
}
3232

33-
public mutating func visitCodeBlock(_ codeBlock: CodeBlock) {
33+
mutating func visitCodeBlock(_ codeBlock: CodeBlock) {
3434
let info = codeBlock.language?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
3535
guard !info.isEmpty else { return }
3636

Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ public enum RenderBlockContent: Equatable {
124124
public var code: [String]
125125
/// Additional metadata for this code block.
126126
public var metadata: RenderContentMetadata?
127-
public var copyToClipboard: Bool = true
127+
public var copyToClipboard: Bool
128128

129129
public enum OptionName: String, CaseIterable {
130130
case nocopy
131131

132-
init?<S: StringProtocol>(caseInsensitive raw: S) {
132+
init?(caseInsensitive raw: some StringProtocol) {
133133
self.init(rawValue: raw.lowercased())
134134
}
135135
}
@@ -139,7 +139,7 @@ public enum RenderBlockContent: Equatable {
139139
}
140140

141141
/// Make a new `CodeListing` with the given data.
142-
public init(syntax: String?, code: [String], metadata: RenderContentMetadata?, copyToClipboard: Bool) {
142+
public init(syntax: String?, code: [String], metadata: RenderContentMetadata?, copyToClipboard: Bool = true) {
143143
self.syntax = syntax
144144
self.code = code
145145
self.metadata = metadata

Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,13 @@ struct RenderContentCompiler: MarkupVisitor {
7070

7171
let options = parseLanguageString(codeBlock.language)
7272

73-
var listing = RenderBlockContent.CodeListing(
73+
let listing = RenderBlockContent.CodeListing(
7474
syntax: options.lang ?? bundle.info.defaultCodeListingLanguage,
7575
code: codeBlock.code.splitByNewlines,
7676
metadata: nil,
77-
copyToClipboard: true // default value
77+
copyToClipboard: options.tokens.contains(.nocopy)
7878
)
7979

80-
// apply code block options
81-
for option in options.tokens {
82-
switch option {
83-
case .nocopy:
84-
listing.copyToClipboard = false
85-
}
86-
}
87-
8880
return [RenderBlockContent.codeListing(listing)]
8981

9082
} else {

0 commit comments

Comments
 (0)