feat: improve text format handling and update documentation

- Optimize HTML to Markdown conversion
- Add smart line break handling
- Preserve formatting while cleaning extra spaces
- Update README with detailed format handling features
- Add text processing highlights section
This commit is contained in:
zhukang 2025-01-15 21:19:42 +08:00
parent c8ba96bcf6
commit 46b7da2a77
2 changed files with 43 additions and 4 deletions

View File

@ -12,6 +12,35 @@
- 🌐 完整的跨平台支持
- 🔄 系统托盘支持,后台运行
- 🎨 自适应系统主题
- 📝 优化的文本格式处理
## 🎯 功能亮点
### 智能格式转换
- **HTML 富文本**
- 保持原始格式(粗体、斜体、链接等)
- 保留图片和表格结构
- 智能处理段落和换行
- 清理多余空白行
- **纯文本处理**
- 自动识别文本编码
- 智能处理中文内容
- 保持段落结构
- 优化换行格式
- **Unicode 支持**
- 完整的 Unicode 字符支持
- 多语言文本兼容
- 保持特殊字符格式
### 格式优化
- 自动清理冗余空行
- 保持段落间距一致
- 优化列表和缩进结构
- 保持代码块格式
## 🚀 快速开始

View File

@ -4,7 +4,7 @@ import configparser
from pynput import mouse
import win32clipboard
import win32con
from html2text import html2text
from html2text import HTML2Text
import keyboard
import threading
import sys
@ -56,21 +56,31 @@ class TextCaptureService:
try:
content = win32clipboard.GetClipboardData(win32con.CF_HTML)
self.logger.info("Clipboard HTML content captured")
return html2text(content)
h = HTML2Text()
h.body_width = 0 # 禁用自动换行
h.single_line_break = True # 使用单行换行
h.ignore_emphasis = False
h.ignore_images = False
h.ignore_links = False
h.ignore_tables = False
return h.handle(content).strip()
except:
pass
try:
content = win32clipboard.GetClipboardData(win32con.CF_TEXT)
self.logger.info("Clipboard TEXT content captured")
return content.decode('gbk')
text = content.decode('gbk')
# 处理纯文本的换行
return '\n'.join(line.strip() for line in text.splitlines() if line.strip())
except:
pass
try:
content = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
self.logger.info("Clipboard UNICODE TEXT content captured")
return content
# 处理Unicode文本的换行
return '\n'.join(line.strip() for line in content.splitlines() if line.strip())
except:
return None