支持外部 Markdown 文件预览与格式化分发

This commit is contained in:
2026-07-13 22:17:12 +08:00
parent df7e74b10e
commit 99b014190d
6 changed files with 306 additions and 119 deletions
+9 -23
View File
@@ -18,6 +18,7 @@ class FormatLogViewController: UIViewController {
private var resetButton: UIBarButtonItem!
private var isFormatted = false
private var rightBarButtonMode: RightBarButtonMode = .paste
var initialText: String?
private enum RightBarButtonMode {
case paste
@@ -30,6 +31,13 @@ class FormatLogViewController: UIViewController {
navigationItem.largeTitleDisplayMode = .never
view.backgroundColor = .systemGroupedBackground
setupUI()
if let initialText = initialText {
textView.text = initialText
isFormatted = true
formatButton.setTitle("保存到 iCloud", for: .normal)
rightBarButtonMode = .reset
updateRightBarButtonItem()
}
setupKeyboardObservers()
}
@@ -151,7 +159,7 @@ class FormatLogViewController: UIViewController {
if isFormatted {
saveToFiles()
} else {
textView.text = formatLog(textView.text)
textView.text = TextFormatter.formatLog(textView.text)
isFormatted = true
formatButton.setTitle("保存到 iCloud", for: .normal)
rightBarButtonMode = .reset
@@ -222,28 +230,6 @@ class FormatLogViewController: UIViewController {
}
return cleanName + ".md"
}
private func formatLog(_ 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: "")
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
content = content.replacingOccurrences(of: "一、生活方面", with: "## 一、生活方面")
content = content.replacingOccurrences(of: "二、交易方面", with: "## 二、交易方面")
content = content.replacingOccurrences(of: "三、工作方面", with: "## 三、工作方面")
return content
}
}
extension FormatLogViewController: UITextViewDelegate {