Skip to content

Commit 53a5aca

Browse files
author
Jesse Haigh
committed
add strikeout option
1 parent 8d87440 commit 53a5aca

File tree

8 files changed

+32
-17
lines changed

8 files changed

+32
-17
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,13 @@ public enum RenderBlockContent: Equatable {
127127
public var copyToClipboard: Bool = true
128128
public var wrap: Int = 100
129129
public var highlight: [Int] = [Int]()
130+
public var strikeout: [Int] = [Int]()
130131

131132
public enum OptionName: String, CaseIterable {
132133
case nocopy
133134
case wrap
134135
case highlight
136+
case strikeout
135137
case unknown
136138

137139
init?<S: StringProtocol>(caseInsensitive raw: S) {
@@ -144,13 +146,14 @@ public enum RenderBlockContent: Equatable {
144146
}
145147

146148
/// Make a new `CodeListing` with the given data.
147-
public init(syntax: String?, code: [String], metadata: RenderContentMetadata?, copyToClipboard: Bool, wrap: Int, highlight: [Int]) {
149+
public init(syntax: String?, code: [String], metadata: RenderContentMetadata?, copyToClipboard: Bool, wrap: Int, highlight: [Int], strikeout: [Int]) {
148150
self.syntax = syntax
149151
self.code = code
150152
self.metadata = metadata
151153
self.copyToClipboard = copyToClipboard
152154
self.wrap = wrap
153155
self.highlight = highlight
156+
self.strikeout = strikeout
154157
}
155158
}
156159

@@ -718,7 +721,7 @@ extension RenderBlockContent.Table: Codable {
718721
extension RenderBlockContent: Codable {
719722
private enum CodingKeys: CodingKey {
720723
case type
721-
case inlineContent, content, caption, style, name, syntax, code, level, text, items, media, runtimePreview, anchor, summary, example, metadata, start, copyToClipboard, wrap, highlight
724+
case inlineContent, content, caption, style, name, syntax, code, level, text, items, media, runtimePreview, anchor, summary, example, metadata, start, copyToClipboard, wrap, highlight, strikeout
722725
case request, response
723726
case header, rows
724727
case numberOfColumns, columns
@@ -747,7 +750,8 @@ extension RenderBlockContent: Codable {
747750
metadata: container.decodeIfPresent(RenderContentMetadata.self, forKey: .metadata),
748751
copyToClipboard: container.decodeIfPresent(Bool.self, forKey: .copyToClipboard) ?? copy,
749752
wrap: container.decodeIfPresent(Int.self, forKey: .wrap) ?? 0,
750-
highlight: container.decodeIfPresent([Int].self, forKey: .highlight) ?? [Int]()
753+
highlight: container.decodeIfPresent([Int].self, forKey: .highlight) ?? [Int](),
754+
strikeout: container.decodeIfPresent([Int].self, forKey: .strikeout) ?? [Int]()
751755
))
752756
case .heading:
753757
self = try .heading(.init(level: container.decode(Int.self, forKey: .level), text: container.decode(String.self, forKey: .text), anchor: container.decodeIfPresent(String.self, forKey: .anchor)))
@@ -854,6 +858,7 @@ extension RenderBlockContent: Codable {
854858
try container.encode(l.copyToClipboard, forKey: .copyToClipboard)
855859
try container.encode(l.wrap, forKey: .wrap)
856860
try container.encode(l.highlight, forKey: .highlight)
861+
try container.encode(l.strikeout, forKey: .strikeout)
857862
case .heading(let h):
858863
try container.encode(h.level, forKey: .level)
859864
try container.encode(h.text, forKey: .text)

Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ struct RenderContentCompiler: MarkupVisitor {
5757
metadata: nil,
5858
copyToClipboard: true, // default value
5959
wrap: 0, // default value
60-
highlight: [Int]() // default value
60+
highlight: [Int](), // default value
61+
strikeout: [Int]() // default value
6162
)
6263

6364
// apply code block options
@@ -72,7 +73,9 @@ struct RenderContentCompiler: MarkupVisitor {
7273
listing.wrap = 0
7374
}
7475
case .highlight:
75-
listing.highlight = parseHighlight(value) ?? []
76+
listing.highlight = parseCodeBlockOptionArray(value) ?? []
77+
case .strikeout:
78+
listing.strikeout = parseCodeBlockOptionArray(value) ?? []
7679
case .unknown:
7780
break
7881
}
@@ -81,7 +84,7 @@ struct RenderContentCompiler: MarkupVisitor {
8184
return [RenderBlockContent.codeListing(listing)]
8285

8386
} else {
84-
return [RenderBlockContent.codeListing(.init(syntax: codeBlock.language ?? bundle.info.defaultCodeListingLanguage, code: codeBlock.code.splitByNewlines, metadata: nil, copyToClipboard: false, wrap: 0, highlight: [Int]()))]
87+
return [RenderBlockContent.codeListing(.init(syntax: codeBlock.language ?? bundle.info.defaultCodeListingLanguage, code: codeBlock.code.splitByNewlines, metadata: nil, copyToClipboard: false, wrap: 0, highlight: [Int](), strikeout: [Int]()))]
8588
}
8689
}
8790

Sources/SwiftDocC/Semantics/Snippets/Snippet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ extension Snippet: RenderableDirectiveConvertible {
8484
let minimumIndentation = lines.map { $0.prefix { $0.isWhitespace }.count }.min() ?? 0
8585
let trimmedLines = lines.map { String($0.dropFirst(minimumIndentation)) }
8686
let copy = FeatureFlags.current.isExperimentalCodeBlockEnabled
87-
return [RenderBlockContent.codeListing(.init(syntax: snippetMixin.language, code: trimmedLines, metadata: nil, copyToClipboard: copy, wrap: 0, highlight: [Int]()))]
87+
return [RenderBlockContent.codeListing(.init(syntax: snippetMixin.language, code: trimmedLines, metadata: nil, copyToClipboard: copy, wrap: 0, highlight: [Int](), strikeout: [Int]()))]
8888
} else {
8989
// Render the whole snippet with its explanation content.
9090
let docCommentContent = snippetEntity.markup.children.flatMap { contentCompiler.visit($0) }
9191
let copy = FeatureFlags.current.isExperimentalCodeBlockEnabled
92-
let code = RenderBlockContent.codeListing(.init(syntax: snippetMixin.language, code: snippetMixin.lines, metadata: nil, copyToClipboard: copy, wrap: 0, highlight: [Int]()))
92+
let code = RenderBlockContent.codeListing(.init(syntax: snippetMixin.language, code: snippetMixin.lines, metadata: nil, copyToClipboard: copy, wrap: 0, highlight: [Int](), strikeout: [Int]()))
9393
return docCommentContent + [code]
9494
}
9595
}

Sources/SwiftDocC/SwiftDocC.docc/Resources/RenderNode.spec.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,12 @@
817817
"items": {
818818
"type": "integer"
819819
}
820+
},
821+
"strikeout": {
822+
"type": "array",
823+
"items": {
824+
"type": "integer"
825+
}
820826
}
821827
}
822828
},

Sources/SwiftDocC/Utility/ParseLanguageString.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
See https://swift.org/LICENSE.txt for license information
88
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
10-
11-
public func parseHighlight(_ value: String?) -> [Int]? {
10+
/// A function that parses array values on code block options from the language line string
11+
public func parseCodeBlockOptionArray(_ value: String?) -> [Int]? {
1212
guard var s = value?.trimmingCharacters(in: .whitespaces), !s.isEmpty else { return [] }
1313

1414
if s.hasPrefix("[") && s.hasSuffix("]") {
@@ -56,6 +56,7 @@ public func tokenizeLanguageString(_ input: String?) -> (lang: String?, tokens:
5656
return (lang, tokens)
5757
}
5858

59+
// helper function for tokenizeLanguageString to parse the language line
5960
func parseLanguageString(_ input: String?) -> [Substring] {
6061

6162
guard let input else { return [] }

Tests/SwiftDocCTests/Model/RenderContentMetadataTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class RenderContentMetadataTests: XCTestCase {
5454
RenderInlineContent.text("Content"),
5555
])
5656

57-
let code = RenderBlockContent.codeListing(.init(syntax: nil, code: [], metadata: metadata, copyToClipboard: false, wrap: 0, highlight: []))
57+
let code = RenderBlockContent.codeListing(.init(syntax: nil, code: [], metadata: metadata, copyToClipboard: false, wrap: 0, highlight: [], strikeout: []))
5858
let data = try JSONEncoder().encode(code)
5959
let roundtrip = try JSONDecoder().decode(RenderBlockContent.self, from: data)
6060

Tests/SwiftDocCTests/Model/RenderNodeSerializationTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class RenderNodeSerializationTests: XCTestCase {
4444
.strong(inlineContent: [.text("Project > Run")]),
4545
.text(" menu item, or the following code:"),
4646
])),
47-
.codeListing(.init(syntax: "swift", code: ["xcrun xcodebuild -h", "xcrun xcodebuild build -configuration Debug"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: [])),
47+
.codeListing(.init(syntax: "swift", code: ["xcrun xcodebuild -h", "xcrun xcodebuild build -configuration Debug"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: [], strikeout: [])),
4848
]))
4949
]
5050

@@ -71,16 +71,16 @@ class RenderNodeSerializationTests: XCTestCase {
7171
let assessment1 = TutorialAssessmentsRenderSection.Assessment(title: [.paragraph(.init(inlineContent: [.text("Lorem ipsum dolor sit amet?")]))],
7272
content: nil,
7373
choices: [
74-
.init(content: [.codeListing(.init(syntax: "swift", code: ["override func viewDidLoad() {", "super.viewDidLoad()", "}"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: []))], isCorrect: true, justification: [.paragraph(.init(inlineContent: [.text("It's correct because...")]))], reaction: "That's right!"),
75-
.init(content: [.codeListing(.init(syntax: "swift", code: ["sceneView.delegate = self"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: []))], isCorrect: false, justification: [.paragraph(.init(inlineContent: [.text("It's incorrect because...")]))], reaction: "Not quite."),
74+
.init(content: [.codeListing(.init(syntax: "swift", code: ["override func viewDidLoad() {", "super.viewDidLoad()", "}"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: [], strikeout: []))], isCorrect: true, justification: [.paragraph(.init(inlineContent: [.text("It's correct because...")]))], reaction: "That's right!"),
75+
.init(content: [.codeListing(.init(syntax: "swift", code: ["sceneView.delegate = self"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: [], strikeout: []))], isCorrect: false, justification: [.paragraph(.init(inlineContent: [.text("It's incorrect because...")]))], reaction: "Not quite."),
7676
.init(content: [.paragraph(.init(inlineContent: [.text("None of the above.")]))], isCorrect: false, justification: [.paragraph(.init(inlineContent: [.text("It's incorrect because...")]))], reaction: nil),
7777
])
7878

7979
let assessment2 = TutorialAssessmentsRenderSection.Assessment(title: [.paragraph(.init(inlineContent: [.text("Duis aute irure dolor in reprehenderit?")]))],
8080
content: [.paragraph(.init(inlineContent: [.text("What is the airspeed velocity of an unladen swallow?")]))],
8181
choices: [
82-
.init(content: [.codeListing(.init(syntax: "swift", code: ["super.viewWillAppear()"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: []))], isCorrect: true, justification: [.paragraph(.init(inlineContent: [.text("It's correct because...")]))], reaction: "Correct."),
83-
.init(content: [.codeListing(.init(syntax: "swift", code: ["sceneView.delegate = self"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: []))], isCorrect: true, justification: [.paragraph(.init(inlineContent: [.text("It's correct because...")]))], reaction: "Yep."),
82+
.init(content: [.codeListing(.init(syntax: "swift", code: ["super.viewWillAppear()"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: [], strikeout: []))], isCorrect: true, justification: [.paragraph(.init(inlineContent: [.text("It's correct because...")]))], reaction: "Correct."),
83+
.init(content: [.codeListing(.init(syntax: "swift", code: ["sceneView.delegate = self"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: [], strikeout: []))], isCorrect: true, justification: [.paragraph(.init(inlineContent: [.text("It's correct because...")]))], reaction: "Yep."),
8484
.init(content: [.paragraph(.init(inlineContent: [.text("None of the above.")]))], isCorrect: false, justification: [.paragraph(.init(inlineContent: [.text("It's incorrect because...")]))], reaction: "Close!"),
8585
])
8686

Tests/SwiftDocCTests/Utility/ListItemExtractorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ class ListItemExtractorTests: XCTestCase {
514514
// ```
515515
// Inner code block
516516
// ```
517-
.codeListing(.init(syntax: nil, code: ["Inner code block"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: [])),
517+
.codeListing(.init(syntax: nil, code: ["Inner code block"], metadata: nil, copyToClipboard: false, wrap: 0, highlight: [], strikeout: [])),
518518

519519
// > Warning: Inner aside, with ``ThirdNotFoundSymbol`` link
520520
.aside(.init(style: .init(asideKind: .warning), content: [

0 commit comments

Comments
 (0)