From 8d117f7f97c1202e7f8f2729eee9c976d9ea1366 Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 12 Jul 2026 22:35:50 +0800 Subject: [PATCH] =?UTF-8?q?iCloud=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E6=AE=B5=E8=90=BD=E7=BB=93=E6=9E=84=E4=BB=A5=E9=85=8D?= =?UTF-8?q?=E5=90=88Note=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Note/FormatNoteViewController.swift | 33 +++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Note/FormatNoteViewController.swift b/Note/FormatNoteViewController.swift index ba4d9cb..455be96 100644 --- a/Note/FormatNoteViewController.swift +++ b/Note/FormatNoteViewController.swift @@ -208,19 +208,30 @@ class FormatNoteViewController: UIViewController { content = content.replacingOccurrences(of: old, with: new) } - content = content.replacingOccurrences(of: "。", with: "。\n") - content = content.replacingOccurrences(of: "?", with: "?\n") - content = removeEmptyLines(content) - content = content.replacingOccurrences(of: ":\\s*", with: ":\n\n", options: .regularExpression) - content = content.replacingOccurrences(of: "。", with: "。\n") - content = content.replacingOccurrences(of: "?", with: "?\n") - content = content.replacingOccurrences(of: ":\n\n", with: ":") - content = content.replacingOccurrences(of: ":一、", with: ":\n\n一、") - content = content.replacingOccurrences(of: " ", with: "") - content = content.replacingOccurrences(of: "---", with: "---\n") content = content.replacingOccurrences(of: "日星期", with: "日 星期") + + // 保留原始段落结构 + let paragraphs = content.components(separatedBy: .newlines) + .split(separator: "", omittingEmptySubsequences: false) + .map { $0.joined(separator: "\n") } + + let formattedParagraphs = paragraphs.map { paragraph -> String in + var p = paragraph + p = p.replacingOccurrences(of: "。", with: "。\n") + p = p.replacingOccurrences(of: "?", with: "?\n") + p = removeEmptyLines(p) + p = p.replacingOccurrences(of: ":\\s*", with: ":\n\n", options: .regularExpression) + p = p.replacingOccurrences(of: "。", with: "。\n") + p = p.replacingOccurrences(of: "?", with: "?\n") + p = p.replacingOccurrences(of: ":\n\n", with: ":") + p = p.replacingOccurrences(of: ":一、", with: ":\n\n一、") + p = p.replacingOccurrences(of: "---", with: "---\n") + p = removeEmptyLines(p) + return p + } + + content = formattedParagraphs.joined(separator: "\n\n") content = "# " + content - content = insertEmptyLineAfterFirstLine(content) return content }