iCloud格式化保留段落结构以配合Note格式化
This commit is contained in:
@@ -208,19 +208,30 @@ class FormatNoteViewController: UIViewController {
|
|||||||
content = content.replacingOccurrences(of: old, with: new)
|
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: "日 星期")
|
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 = "# " + content
|
||||||
content = insertEmptyLineAfterFirstLine(content)
|
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user