Compare commits
4 Commits
4ad0c64bdb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cdaa195c7 | ||
|
|
7cea83cf2d | ||
|
|
c763586ff3 | ||
|
|
1918e07b65 |
1
format_text/journal/1.md
Normal file
1
format_text/journal/1.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#
|
||||||
46
format_text/journal/formatter_cloud.py
Normal file
46
format_text/journal/formatter_cloud.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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)
|
||||||
1
format_text/readbook/1.md
Normal file
1
format_text/readbook/1.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#
|
||||||
79
format_text/readbook/formatter_cloud.py
Normal file
79
format_text/readbook/formatter_cloud.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
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('# ', '').replace('#', '') # 去#
|
||||||
|
content = content.replace('!', '。').replace('!', '。') # 替换感叹号为句号
|
||||||
|
content = content.replace(';', '。').replace(';', '。') # 替换分号为句号
|
||||||
|
content = content.replace('.', '。') # 替换半角句号为全角
|
||||||
|
content = content.replace('(', '(').replace(')', ')') # 统一括号
|
||||||
|
content = content.replace('?', '?').replace(',', ',') # 统一问号和逗号
|
||||||
|
content = content.replace(':', ':') # 替换半角冒号为全角
|
||||||
|
content = content.replace('10、', '十、') # 替换文案
|
||||||
|
content = content.replace('11、', '十一、') # 替换文案
|
||||||
|
content = content.replace('12、', '十二、') # 替换文案
|
||||||
|
content = content.replace('13、', '十三、') # 替换文案
|
||||||
|
content = content.replace('14、', '十四、') # 替换文案
|
||||||
|
content = content.replace('15、', '十五、') # 替换文案
|
||||||
|
content = content.replace('16、', '十六、') # 替换文案
|
||||||
|
content = content.replace('17、', '十七、') # 替换文案
|
||||||
|
content = content.replace('18、', '十八、') # 替换文案
|
||||||
|
content = content.replace('19、', '十九、') # 替换文案
|
||||||
|
content = content.replace('20、', '二十、') # 替换文案
|
||||||
|
content = content.replace('1、', '一、') # 替换文案
|
||||||
|
content = content.replace('2、', '二、') # 替换文案
|
||||||
|
content = content.replace('3、', '三、') # 替换文案
|
||||||
|
content = content.replace('4、', '四、') # 替换文案
|
||||||
|
content = content.replace('5、', '五、') # 替换文案
|
||||||
|
content = content.replace('6、', '六、') # 替换文案
|
||||||
|
content = content.replace('7、', '七、') # 替换文案
|
||||||
|
content = content.replace('8、', '八、') # 替换文案
|
||||||
|
content = content.replace('9、', '九、') # 替换文案
|
||||||
|
|
||||||
|
# 处理句号和问号后的换行(首次处理)
|
||||||
|
content = content.replace('。', '。\n').replace('?', '?\n')
|
||||||
|
|
||||||
|
# 去除空白行(先过滤原始文本中的空行)
|
||||||
|
lines = content.splitlines()
|
||||||
|
non_empty_lines = [line for line in lines if line.strip()]
|
||||||
|
content = '\n'.join(non_empty_lines)
|
||||||
|
|
||||||
|
# 在冒号后添加空行(关键调整:放在去空行之后,避免被过滤)
|
||||||
|
content = re.sub(r':\s*', r':\n\n', content) # 冒号后添加两个换行(空一行)
|
||||||
|
|
||||||
|
# 再次处理句号和问号换行(确保标点后换行生效)
|
||||||
|
content = content.replace('。', '。\n').replace('?', '?\n')
|
||||||
|
|
||||||
|
# 再次处理:换行
|
||||||
|
content = content.replace(':\n\n', ':')
|
||||||
|
content = content.replace(':一、', ':\n\n一、')
|
||||||
|
content = content.replace(' ', '') # 去空格
|
||||||
|
|
||||||
|
# 处理分隔线和日期格式
|
||||||
|
content = content.replace('---', '---\n') # 分隔线后换行
|
||||||
|
content = content.replace('日星期', '日 星期') # 调整日期格式
|
||||||
|
|
||||||
|
# 添加标题和第二行空行
|
||||||
|
content = '# ' + content # 首行添加#
|
||||||
|
lines = content.splitlines()
|
||||||
|
if len(lines) > 0:
|
||||||
|
lines.insert(1, '') # 第二行插入空行
|
||||||
|
content = '\n'.join(lines)
|
||||||
|
|
||||||
|
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)
|
||||||
61
format_text/readbook/formatter_note.py
Normal file
61
format_text/readbook/formatter_note.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
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.replace('?', '?')
|
||||||
|
# 将,转为,
|
||||||
|
content = content.replace(',', ',')
|
||||||
|
# 将:转为:
|
||||||
|
content = content.replace(':', ':')
|
||||||
|
# 让句号后的文案换行
|
||||||
|
content = content.replace('。', '。\n')
|
||||||
|
# 让?后的文案换行
|
||||||
|
content = content.replace('?', '?\n')
|
||||||
|
# 去除空白行
|
||||||
|
lines = content.splitlines()
|
||||||
|
non_empty_lines = [line for line in lines if line.strip()]
|
||||||
|
content = '\n'.join(non_empty_lines)
|
||||||
|
# 让---后的文案换行
|
||||||
|
content = content.replace('---', '')
|
||||||
|
# 将 日星期 转为:日 星期
|
||||||
|
content = content.replace('日星期', '日 星期')
|
||||||
|
# 在第二行插入空白行
|
||||||
|
lines = content.splitlines()
|
||||||
|
if len(lines) > 0:
|
||||||
|
lines.insert(1, '')
|
||||||
|
content = '\n'.join(lines)
|
||||||
|
|
||||||
|
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)
|
||||||
5
format_text/start.sh
Normal file
5
format_text/start.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
# 获取脚本本身所在目录的绝对路径(万能写法,无论在哪执行脚本都生效)
|
||||||
|
SCRIPT_DIR=$(cd $(dirname $0) && pwd)
|
||||||
|
sudo docker run -itd --name text_format_python -v "$SCRIPT_DIR":/app python:3.13.7-alpine3.22
|
||||||
Reference in New Issue
Block a user