From 0c14b89125434a6456f41959fe1a8572c0706b9a Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 12 Jul 2026 22:32:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DNote=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E6=AE=B5=E8=90=BD=E7=BB=93=E6=9E=84=E5=A4=B1=E7=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Note/FormatNoteViewController.swift | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Note/FormatNoteViewController.swift b/Note/FormatNoteViewController.swift index 36dfa29..ba4d9cb 100644 --- a/Note/FormatNoteViewController.swift +++ b/Note/FormatNoteViewController.swift @@ -226,7 +226,6 @@ class FormatNoteViewController: UIViewController { private func formatForNote(_ text: String) -> String { var content = text - content = content.replacingOccurrences(of: " ", with: "") content = content.replacingOccurrences(of: "# ", with: "") content = content.replacingOccurrences(of: "#", with: "") content = content.replacingOccurrences(of: "!", with: "。") @@ -242,18 +241,14 @@ class FormatNoteViewController: UIViewController { content = content.replacingOccurrences(of: "---", with: "") 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) - return p + removeEmptyLines(paragraph) } return formattedParagraphs.joined(separator: "\n\n\n")