Note格式化按---分段并移除句间空行
This commit is contained in:
@@ -228,25 +228,10 @@ class FormatNoteViewController: UIViewController {
|
|||||||
var content = text
|
var content = text
|
||||||
content = content.replacingOccurrences(of: "# ", with: "")
|
content = content.replacingOccurrences(of: "# ", with: "")
|
||||||
content = content.replacingOccurrences(of: "#", with: "")
|
content = content.replacingOccurrences(of: "#", with: "")
|
||||||
content = content.replacingOccurrences(of: "!", with: "。")
|
|
||||||
content = content.replacingOccurrences(of: "!", with: "。")
|
|
||||||
content = content.replacingOccurrences(of: ";", with: "。")
|
|
||||||
content = content.replacingOccurrences(of: ";", with: "。")
|
|
||||||
content = content.replacingOccurrences(of: ".", with: "。")
|
|
||||||
content = content.replacingOccurrences(of: "(", with: "(")
|
|
||||||
content = content.replacingOccurrences(of: ")", with: ")")
|
|
||||||
content = content.replacingOccurrences(of: "?", with: "?")
|
|
||||||
content = content.replacingOccurrences(of: ",", with: ",")
|
|
||||||
content = content.replacingOccurrences(of: ":", with: ":")
|
|
||||||
content = content.replacingOccurrences(of: "---", with: "")
|
|
||||||
content = content.replacingOccurrences(of: "日星期", with: "日 星期")
|
content = content.replacingOccurrences(of: "日星期", with: "日 星期")
|
||||||
|
|
||||||
// 按原始空行分割段落,保留段落结构
|
// 按 --- 分割段落,移除每个段落内部的空行,段落之间保留两个空行
|
||||||
let paragraphs = content.components(separatedBy: .newlines)
|
let paragraphs = content.components(separatedBy: "---")
|
||||||
.split(separator: "", omittingEmptySubsequences: false)
|
|
||||||
.map { $0.joined(separator: "\n") }
|
|
||||||
|
|
||||||
// 清理每个段落内部的多余空行,段落之间保留两个空行
|
|
||||||
let formattedParagraphs = paragraphs.map { paragraph -> String in
|
let formattedParagraphs = paragraphs.map { paragraph -> String in
|
||||||
removeEmptyLines(paragraph)
|
removeEmptyLines(paragraph)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user