Compare commits

..

15 Commits

4 changed files with 171 additions and 113 deletions
+8 -8
View File
@@ -262,14 +262,14 @@
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault;
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = UIInterfaceOrientationPortrait;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fishestlife.note.Note;
MARKETING_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fishestlife.note;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
SDKROOT = auto;
@@ -306,14 +306,14 @@
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault;
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = UIInterfaceOrientationPortrait;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fishestlife.note.Note;
MARKETING_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fishestlife.note;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
SDKROOT = auto;
+76 -59
View File
@@ -9,60 +9,30 @@ import SwiftUI
struct FormatterView: View {
@State private var inputText: String = ""
@State private var outputText: String = ""
@State private var showEmptyAlert: Bool = false
@State private var showCopied: Bool = false
var body: some View {
NavigationStack {
VStack(spacing: 16) {
TextEditor(text: $inputText)
.frame(minHeight: 120)
.padding(8)
.background(Color(.systemGray6))
.cornerRadius(8)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color(.systemGray4), lineWidth: 1)
)
VStack(spacing: 0) {
inputArea
.frame(maxHeight: .infinity)
Button(action: formatText) {
Label("格式化", systemImage: "wand.and.stars")
.font(.headline)
.frame(maxWidth: .infinity)
.padding()
.background(Color.accentColor)
.foregroundStyle(.white)
.cornerRadius(10)
actionArea
}
if !outputText.isEmpty {
VStack(alignment: .leading, spacing: 8) {
HStack {
Text("格式化结果")
.font(.subheadline)
.foregroundStyle(.secondary)
Spacer()
Button(action: copyOutput) {
Image(systemName: "doc.on.doc")
}
}
TextEditor(text: .constant(outputText))
.frame(minHeight: 120)
.padding(8)
.background(Color(.systemGray6))
.cornerRadius(8)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color(.systemGray4), lineWidth: 1)
)
}
}
Spacer()
}
.padding()
.background(Color(.systemGroupedBackground).ignoresSafeArea())
.navigationTitle("文案格式化")
.navigationBarTitleDisplayMode(.large)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
MoreMenuBarButton(text: $inputText, showCopied: $showCopied)
}
}
.alert("提示", isPresented: $showEmptyAlert) {
Button("确定", role: .cancel) {}
} message: {
Text("请输入需要格式化的文案")
}
.overlay {
if showCopied {
VStack {
@@ -82,7 +52,64 @@ struct FormatterView: View {
}
}
private var inputArea: some View {
VStack(alignment: .leading, spacing: 8) {
Text("输入")
.font(.subheadline)
.foregroundStyle(.secondary)
.padding(.horizontal)
TextEditor(text: $inputText)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(12)
.background(Color(.systemBackground))
.cornerRadius(12)
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color(.systemGray4), lineWidth: 1)
)
.padding(.horizontal)
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button("完成") {
dismissKeyboard()
}
}
}
Text("粘贴需要格式化的文案")
.font(.subheadline)
.foregroundStyle(.secondary)
.padding(.horizontal)
}
.padding(.vertical, 8)
}
private var actionArea: some View {
Button(action: formatText) {
Label("格式化", systemImage: "wand.and.stars")
.font(.headline)
.frame(maxWidth: .infinity)
.padding()
.background(Color(.systemBackground))
.foregroundStyle(Color.accentColor)
.cornerRadius(12)
}
.padding()
.background(Color(.systemGroupedBackground))
}
private func dismissKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
private func formatText() {
if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
showEmptyAlert = true
return
}
var content = inputText
// #
@@ -113,20 +140,10 @@ struct FormatterView: View {
content = content.replacingOccurrences(of: "二、交易方面", with: "## 二、交易方面")
content = content.replacingOccurrences(of: "三、工作方面", with: "## 三、工作方面")
outputText = content
inputText = content
dismissKeyboard()
}
private func copyOutput() {
UIPasteboard.general.string = outputText
withAnimation {
showCopied = true
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
withAnimation {
showCopied = false
}
}
}
}
#Preview {
+87
View File
@@ -0,0 +1,87 @@
//
// MoreMenuBarButton.swift
// Note
//
// Created by fish on 2026/7/12.
//
import SwiftUI
struct MoreMenuBarButton: UIViewRepresentable {
@Binding var text: String
@Binding var showCopied: Bool
func makeUIView(context: Context) -> UIView {
let button = makeGlassButton()
button.menu = context.coordinator.makeMenu()
button.showsMenuAsPrimaryAction = true
let barButtonItem = UIBarButtonItem(customView: button)
context.coordinator.barButtonItem = barButtonItem
context.coordinator.button = button
return button
}
func updateUIView(_ uiView: UIView, context: Context) {
context.coordinator.button?.menu = context.coordinator.makeMenu()
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
private func makeGlassButton() -> UIButton {
let button = UIButton(type: .system)
button.setImage(UIImage(systemName: "ellipsis"), for: .normal)
button.tintColor = UIColor.label
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.layer.cornerRadius = 22
button.clipsToBounds = true
let blurEffect = UIBlurEffect(style: .systemUltraThinMaterial)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = button.bounds
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
blurView.isUserInteractionEnabled = false
button.insertSubview(blurView, at: 0)
return button
}
class Coordinator {
var parent: MoreMenuBarButton
weak var barButtonItem: UIBarButtonItem?
weak var button: UIButton?
init(_ parent: MoreMenuBarButton) {
self.parent = parent
}
func makeMenu() -> UIMenu {
let copyAction = UIAction(
title: "复制",
image: UIImage(systemName: "doc.on.doc"),
attributes: parent.text.isEmpty ? .disabled : [],
handler: { [weak self] _ in
UIPasteboard.general.string = self?.parent.text ?? ""
self?.parent.showCopied = true
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
self?.parent.showCopied = false
}
}
)
let clearAction = UIAction(
title: "清除",
image: UIImage(systemName: "xmark.circle"),
attributes: parent.text.isEmpty ? [.disabled, .destructive] : .destructive,
handler: { [weak self] _ in
self?.parent.text = ""
}
)
return UIMenu(title: "", children: [copyAction, clearAction])
}
}
}
-46
View File
@@ -1,46 +0,0 @@
import os
def format_md_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# 去#
content = content.replace('# ', '')
content = content.replace('#', '')
# 将;转为句号
content = content.replace(';', '')
# 将;转为句号
content = content.replace('', '')
# 将.转为句号
content = content.replace('.', '')
# 将(转为(
content = content.replace('', '(')
# 将)转为)
content = content.replace('', ')')
# 将?转为?
content = content.replace('?', '')
# 将,转为,
content = content.replace(',', '')
# 将:转为:
content = content.replace(':', '')
# 将 日星期 转为:日 星期
content = content.replace('日星期', '日 星期')
# 在第一行插入 #
content = '# ' + content
# 标题设置
content = content.replace('一、生活方面', '## 一、生活方面')
content = content.replace('二、交易方面', '## 二、交易方面')
content = content.replace('三、工作方面', '## 三、工作方面')
with open(file_path, 'w', encoding='utf-8') as file:
file.write(content)
if __name__ == "__main__":
current_dir = os.path.dirname(os.path.abspath(__file__))
print(current_dir)
for root, dirs, files in os.walk(current_dir):
for file in files:
if file.endswith('.md'):
file_path = os.path.join(root, file)
format_md_file(file_path)