Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d117f7f97 | |||
| 0c14b89125 |
@@ -208,25 +208,35 @@ 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
|
||||
}
|
||||
|
||||
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 +252,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