快捷指令预处理去掉标题前缀

This commit is contained in:
2026-07-15 23:19:32 +08:00
parent 1f94b9884c
commit a386802a55
2 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ struct SaveClipIntent: AppIntent {
return .result(value: "剪贴板没有有效文本,未保存。") return .result(value: "剪贴板没有有效文本,未保存。")
} }
let formattedText = TextFormatter.formatForCloud(trimmed) let formattedText = TextFormatter.formatForShortcut(trimmed)
try await ClipStore.shared.save(text: formattedText, source: source) try await ClipStore.shared.save(text: formattedText, source: source)
return .result(value: "已保存到收集箱。") return .result(value: "已保存到收集箱。")
} }
+7 -2
View File
@@ -32,6 +32,13 @@ enum TextFormatter {
} }
static func formatForCloud(_ text: String) -> String { static func formatForCloud(_ text: String) -> String {
var content = formatForShortcut(text)
content = "# " + content
content = insertEmptyLineAfterFirstLine(content)
return content
}
static func formatForShortcut(_ text: String) -> String {
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: "")
@@ -71,8 +78,6 @@ enum TextFormatter {
content = content.replacingOccurrences(of: " ", with: "") content = content.replacingOccurrences(of: " ", with: "")
content = content.replacingOccurrences(of: "---", with: "---\n") content = content.replacingOccurrences(of: "---", with: "---\n")
content = content.replacingOccurrences(of: "日星期", with: "日 星期") content = content.replacingOccurrences(of: "日星期", with: "日 星期")
content = "# " + content
content = insertEmptyLineAfterFirstLine(content)
return content return content
} }