Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Join the wrapped lines of plain text release notes
Țugui Dragoș50f9abf43908
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotes.swift b/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotes.swiftindex 407c8707..2156358a 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotes.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotes.swift@@ -38,16 +38,29 @@ public struct ReleaseNotes: Sendable, Hashable, Codable {}}+ /// Each line is a paragraph or, after a bullet, a list item, and an indented line goes on with the one above,+ /// the way plain text wraps a long item.private static func plainTextBlocks(_ text: String) -> [Block] {- text.split(whereSeparator: \.isNewline).compactMap { line in- let words = line.trimmingCharacters(in: .whitespaces)- guard !words.isEmpty else { return nil }- if let marker = ["• ", "- ", "* "].first(where: words.hasPrefix) {- let item = words.dropFirst(marker.count).trimmingCharacters(in: .whitespaces)- return item.isEmpty ? nil : .item(AttributedString(item), depth: 0)+ var blocks: [Block] = []+ var goesOn = false+ for line in text.split(omittingEmptySubsequences: false, whereSeparator: \.isNewline) {+ let words = line.trimmingCharacters(in: .whitespacesAndNewlines)+ if words.isEmpty {+ goesOn = false+ } else if let mark = words.first, "•-*".contains(mark), words.dropFirst().first?.isWhitespace ?? true {+ let item = words.dropFirst().trimmingCharacters(in: .whitespaces)+ if !item.isEmpty {+ blocks.append(.item(AttributedString(item), depth: 0))+ }+ goesOn = !item.isEmpty+ } else if goesOn, line.first?.isWhitespace == true, let last = blocks.popLast() {+ blocks.append(last.goingOn(with: words))+ } else {+ blocks.append(.paragraph(AttributedString(words)))+ goesOn = true}- return .paragraph(AttributedString(words))}+ return blocks}private static func markdownBlocks(_ text: String) -> [Block] {@@ -82,6 +95,17 @@ public struct ReleaseNotes: Sendable, Hashable, Codable {}}+extension ReleaseNotes.Block {+ /// The block with `words` after its own, as one line wrapped onto the next.+ fileprivate func goingOn(with words: String) -> ReleaseNotes.Block {+ switch self {+ case .heading(let text): .heading(text + AttributedString(" " + words))+ case .paragraph(let text): .paragraph(text + AttributedString(" " + words))+ case .item(let text, let depth): .item(text + AttributedString(" " + words), depth: depth)+ }+ }+}+extension AttributedString {/// The text without the white space around it, or nil when nothing else is left.fileprivate var trimmed: AttributedString? {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesTests.swiftindex 4b35b344..46e4b82b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesTests.swift@@ -33,6 +33,14 @@ struct ReleaseNotesTests {#expect(outline(notes) == ["p What’s new:", "i0 Faster search", "i0 Fixed a crash", "p Thanks for using it!"])}+ @Test func joinsTheIndentedLinesThatContinueAnItem() {+ let text = "Bug Fixes:\r\n- Fixed the API not reporting\n hyperlinks.\n- Fixed a crash\n- \nLine one\nLine two"++ #expect(outline(ReleaseNotes(text, format: .plainText)) == [+ "p Bug Fixes:", "i0 Fixed the API not reporting hyperlinks.", "i0 Fixed a crash", "p Line one", "p Line two",+ ])+ }+@Test func readsMarkdownBlocksAndKeepsOnlySecureLinks() {let markdown = """## 2.0