Skip to content
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
16 changes: 16 additions & 0 deletions CheatSheetTests/Sources/DisplayLineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ struct DisplayLineTests {
#expect(parsed.isComplete == false)
}

@Test func headingKeepsTrailingHashInLanguageNames() {
// Regression: trimmingCharacters(in:) trimmed both ends, so "# C#"
// rendered as "C" in both the editor and the widget.
#expect("# C#".parsedChecklistLine.text == "C#")
#expect("# F#".parsedChecklistLine.text == "F#")
#expect("# C# vs F#".parsedChecklistLine.text == "C# vs F#")
}

@Test func headingStripsOnlyLeadingHashes() {
let parsed = "## Objective-C".parsedChecklistLine

#expect(parsed.text == "Objective-C")
#expect(parsed.isHeading)
#expect(parsed.isTask == false)
}

@Test func parsesCompleteTaskLine() {
let parsed = "- [x] Run build".parsedChecklistLine

Expand Down
5 changes: 4 additions & 1 deletion Shared/Sources/DisplayLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public extension String {

if line.hasPrefix("#") {
isHeading = true
line = line.trimmingCharacters(in: CharacterSet(charactersIn: "# "))
// Strip only the LEADING hashes. trimmingCharacters(in:) works on both
// ends, which silently ate the trailing "#" of headings like "# C#"
// and "# F#" -- on a developer cheat sheet those are content.
line = String(line.drop(while: { $0 == "#" })).trimmingCharacters(in: .whitespaces)
}

let markers = ["- [x] ", "* [x] ", "[x] ", "- [X] ", "* [X] ", "[X] "]
Expand Down
Loading