diff --git a/CheatSheetTests/Sources/DisplayLineTests.swift b/CheatSheetTests/Sources/DisplayLineTests.swift index d5ca934..7d9aaa3 100644 --- a/CheatSheetTests/Sources/DisplayLineTests.swift +++ b/CheatSheetTests/Sources/DisplayLineTests.swift @@ -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 diff --git a/Shared/Sources/DisplayLine.swift b/Shared/Sources/DisplayLine.swift index 2c2580f..75a8109 100644 --- a/Shared/Sources/DisplayLine.swift +++ b/Shared/Sources/DisplayLine.swift @@ -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] "]