用于将文本文件转化为markdown格式
Project description
Text to Markdown Converter
一个简单而强大的文本文件转Markdown格式的Python工具。
功能特性
- 🚀 自动识别标题: 智能识别文本中的标题并转换为Markdown标题格式
- 📝 段落处理: 自动处理普通段落文本
- 📋 列表转换: 支持多种列表格式的识别和转换
- 🔧 编码支持: 自动检测文件编码,支持UTF-8、GBK等多种编码
- 💻 命令行工具: 提供便捷的命令行接口
- 📦 Python API: 提供简洁的Python编程接口
安装
# 从源码安装
pip install -e .
# 安装开发依赖
pip install -e .[dev]
# 安装增强功能依赖
pip install -e .[enhanced]
快速开始
命令行使用
# 基本用法
python -m text_to_markdown_jxppx.tt_md input.txt
# 指定输出文件
python -m text_to_markdown_jxppx.tt_md input.txt output.md
# 或者直接运行脚本
python text_to_markdown_jxppx/tt_md.py example.txt
Python API
from text_to_markdown_jxppx.tt_md import convert_text_to_markdown, TextToMarkdownConverter
# 简单转换
output_path = convert_text_to_markdown('input.txt')
print(f"转换完成: {output_path}")
# 指定输出文件
convert_text_to_markdown('input.txt', 'output.md')
# 使用转换器类进行更多控制
converter = TextToMarkdownConverter()
result = converter.convert_file('input.txt', encoding='gbk')
转换规则
标题识别
工具会自动识别以下类型的标题:
- 全大写短行 →
# 标题(一级标题) - 数字开头的行 (如 "1. 标题", "1.1 标题") →
## 标题(二级标题) - 短行文本 (少于30字符) →
### 标题(三级标题)
列表转换
支持多种列表格式:
- 项目→- 项目* 项目→- 项目1. 项目→- 项目a. 项目→- 项目
示例
输入文本:
PYTHON编程指南
Python是一种高级编程语言。
1. 基础语法
Python使用缩进来表示代码块。
常用数据类型:
- 整数 (int)
- 字符串 (str)
- 列表 (list)
输出Markdown:
# PYTHON编程指南
Python是一种高级编程语言。
## 基础语法
Python使用缩进来表示代码块。
### 常用数据类型:
- 整数 (int)
- 字符串 (str)
- 列表 (list)
依赖说明
核心功能
本工具仅使用Python标准库,无需安装额外依赖:
re- 正则表达式处理os- 文件系统操作pathlib- 路径处理typing- 类型提示
可选依赖
开发依赖 (pip install -e .[dev])
pytest>=7.0.0- 单元测试框架pytest-cov>=4.0.0- 测试覆盖率black>=22.0.0- 代码格式化工具flake8>=5.0.0- 代码质量检查
增强功能 (pip install -e .[enhanced])
chardet>=5.0.0- 自动检测文件编码python-magic>=0.4.27- 文件类型检测
开发
# 克隆项目
git clone <repository-url>
cd text_to_markdown
# 安装开发环境
pip install -e .[dev]
# 运行测试
pytest
# 代码格式化
black .
# 代码检查
flake8
许可证
MIT License
贡献
欢迎提交Issue和Pull Request!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file text_to_markdown_jxppx-1.0.0.tar.gz.
File metadata
- Download URL: text_to_markdown_jxppx-1.0.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a8268e59376b9ae4c37d7b12b2313db326805936b5bca70a6efe84e15109eb
|
|
| MD5 |
3b0f64ee1b53eafc7129889408d7333d
|
|
| BLAKE2b-256 |
ed068f8ac8174aeb89596c301ff222f3e3c0d93b9e1c3c80d4accbce99f7c47c
|
File details
Details for the file text_to_markdown_jxppx-1.0.0-py3-none-any.whl.
File metadata
- Download URL: text_to_markdown_jxppx-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3e57ac42452fe20da74693b4b9813d8987a60f71d4bad9903fc22e3deaf5dc2
|
|
| MD5 |
7927128b8682ba4bce7890dd7ead7262
|
|
| BLAKE2b-256 |
98d4b90437b69034d12db9b21e14ec8523d816dc3cc0bed2c27a9b64ed9f2449
|