From e86c5e183cebd3a1da03ebdc0ccd3cf853766459 Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 12 Jul 2026 22:27:35 +0800 Subject: [PATCH] =?UTF-8?q?Note=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=AE=B5?= =?UTF-8?q?=E8=90=BD=E4=B9=8B=E9=97=B4=E6=94=B9=E4=B8=BA=E4=B8=A4=E8=A1=8C?= =?UTF-8?q?=E9=97=B4=E8=B7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Note/FormatNoteViewController.swift | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Note/FormatNoteViewController.swift b/Note/FormatNoteViewController.swift index a5cebf5..39ca2c1 100644 --- a/Note/FormatNoteViewController.swift +++ b/Note/FormatNoteViewController.swift @@ -223,13 +223,24 @@ class FormatNoteViewController: UIViewController { content = content.replacingOccurrences(of: "?", with: "?") content = content.replacingOccurrences(of: ",", with: ",") content = content.replacingOccurrences(of: ":", with: ":") - content = content.replacingOccurrences(of: "。", with: "。\n") - content = content.replacingOccurrences(of: "?", with: "?\n") - content = removeEmptyLines(content) content = content.replacingOccurrences(of: "---", with: "") content = content.replacingOccurrences(of: "日星期", with: "日 星期") - content = insertEmptyLineAfterFirstLine(content) - return content + + // 按原始空行分割段落 + 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) + return p + } + + return formattedParagraphs.joined(separator: "\n\n\n") } private func saveToFiles() {