修复Note格式化段落结构失真
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user