indexdoc-converter 0.2.1__py3-none-any.whl → 0.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- indexdoc_converter/excel_to_md.py +1 -1
- indexdoc_converter/html_to_md.py +1 -1
- indexdoc_converter/pptx_to_md.py +124 -29
- indexdoc_converter-0.2.3.dist-info/METADATA +228 -0
- {indexdoc_converter-0.2.1.dist-info → indexdoc_converter-0.2.3.dist-info}/RECORD +7 -7
- indexdoc_converter-0.2.1.dist-info/METADATA +0 -92
- {indexdoc_converter-0.2.1.dist-info → indexdoc_converter-0.2.3.dist-info}/WHEEL +0 -0
- {indexdoc_converter-0.2.1.dist-info → indexdoc_converter-0.2.3.dist-info}/top_level.txt +0 -0
indexdoc_converter/html_to_md.py
CHANGED
|
@@ -10,7 +10,7 @@ from PIL import Image
|
|
|
10
10
|
from readability import Document
|
|
11
11
|
import html2text
|
|
12
12
|
|
|
13
|
-
from utils.img_to_base64 import Image2Base64
|
|
13
|
+
from indexdoc_converter.utils.img_to_base64 import Image2Base64
|
|
14
14
|
|
|
15
15
|
# ============ 图片下载和处理类 ============
|
|
16
16
|
class ImageDownloader:
|
indexdoc_converter/pptx_to_md.py
CHANGED
|
@@ -2,78 +2,173 @@ import pptx2md
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
import tempfile
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from indexdoc_converter.utils.img_to_base64 import OutputFormat
|
|
8
|
+
from indexdoc_converter.utils.img_to_base64 import Image2Base64
|
|
9
|
+
from indexdoc_converter.utils import IDUtil
|
|
10
|
+
|
|
11
|
+
def replace_img_with_base64(md_file: Path, img_dir: Path, del_temp_img: bool = True):
|
|
12
|
+
"""
|
|
13
|
+
终极修复版:解决URL编码(%5C)、Windows反斜杠、相对/绝对路径等所有匹配问题
|
|
14
|
+
:param md_file: 生成的MD文件路径
|
|
15
|
+
:param img_dir: pptx2md导出的临时图片目录
|
|
16
|
+
:param del_temp_img: 是否删除临时图片/目录(推荐True)
|
|
17
|
+
"""
|
|
18
|
+
import urllib.parse # 内置库,无需额外安装,处理URL编码/解码
|
|
19
|
+
|
|
20
|
+
if not md_file.exists() or not img_dir.is_dir():
|
|
21
|
+
print(f"⚠ 跳过Base64替换:MD文件或图片目录不存在")
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
# 1. 读取MD内容,保留原始编码格式
|
|
25
|
+
with open(md_file, 'r', encoding='utf-8') as f:
|
|
26
|
+
md_content = f.read()
|
|
27
|
+
|
|
28
|
+
img_path_2_b64 = {}
|
|
29
|
+
# 2. 遍历临时图片,生成所有需要匹配的路径格式 + Base64映射
|
|
30
|
+
for img_file in img_dir.glob("*.*"):
|
|
31
|
+
if not img_file.is_file():
|
|
32
|
+
continue
|
|
33
|
+
try:
|
|
34
|
+
# 调用你的Base64工具类生成MD格式的Base64(参数可按需求调整)
|
|
35
|
+
b64_md_str = Image2Base64.convert_file(
|
|
36
|
+
image_path=img_file,
|
|
37
|
+
max_dim=1200,
|
|
38
|
+
max_kb=200,
|
|
39
|
+
force_webp=True,
|
|
40
|
+
out_format=OutputFormat.MARKDOWN_ALT,
|
|
41
|
+
quality=80
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# 关键:生成5种需要替换的路径格式,覆盖pptx2md所有生成情况
|
|
45
|
+
img_dir_name = img_dir.name # 临时目录名(如4fb6cc7bfcbb11f0aefebc2411ecbf31_pptx_imgs)
|
|
46
|
+
img_name = img_file.name # 图片名(如测试文件_0.jpg)
|
|
47
|
+
# 格式1:绝对路径(C:\Temp\xxx_imgs\测试文件_0.jpg)
|
|
48
|
+
img_path_2_b64[str(img_file)] = b64_md_str
|
|
49
|
+
# 格式2:纯文件名(测试文件_0.jpg)
|
|
50
|
+
img_path_2_b64[img_name] = b64_md_str
|
|
51
|
+
# 格式3:Windows原始反斜杠相对路径(xxx_imgs\测试文件_0.jpg)
|
|
52
|
+
win_relative_path = f"{img_dir_name}\\{img_name}"
|
|
53
|
+
img_path_2_b64[win_relative_path] = b64_md_str
|
|
54
|
+
# 格式4:URL编码后的相对路径(xxx_imgs%5C测试文件_0.jpg)【核心修复项】
|
|
55
|
+
url_encoded_path = urllib.parse.quote(win_relative_path, safe='')
|
|
56
|
+
img_path_2_b64[url_encoded_path] = b64_md_str
|
|
57
|
+
# 格式5:正斜杠相对路径(xxx_imgs/测试文件_0.jpg)【兼容兜底】
|
|
58
|
+
slash_relative_path = f"{img_dir_name}/{img_name}"
|
|
59
|
+
img_path_2_b64[slash_relative_path] = b64_md_str
|
|
60
|
+
|
|
61
|
+
except Exception as e:
|
|
62
|
+
print(f"⚠ 单张图片转Base64失败: {img_file.name} | 错误: {e}")
|
|
63
|
+
continue
|
|
64
|
+
|
|
65
|
+
# 3. 批量替换:按「长路径优先」替换,避免短路径匹配冲突
|
|
66
|
+
# 排序:路径越长越先替换,防止纯文件名先匹配导致长路径替换失败
|
|
67
|
+
for raw_img_path in sorted(img_path_2_b64.keys(), key=len, reverse=True):
|
|
68
|
+
md_content = md_content.replace('', img_path_2_b64[raw_img_path])
|
|
69
|
+
|
|
70
|
+
# 4. 重写MD文件,写入Base64内嵌内容
|
|
71
|
+
with open(md_file, 'w', encoding='utf-8') as f:
|
|
72
|
+
f.write(md_content)
|
|
73
|
+
|
|
74
|
+
# 5. 清理临时图片目录,避免冗余
|
|
75
|
+
if del_temp_img:
|
|
76
|
+
try:
|
|
77
|
+
import shutil
|
|
78
|
+
shutil.rmtree(img_dir)
|
|
79
|
+
print(f"✅ 清理临时图片目录完成: {img_dir.name}")
|
|
80
|
+
except Exception as e:
|
|
81
|
+
print(f"⚠ 临时图片目录清理失败: {e}")
|
|
6
82
|
|
|
7
83
|
def pptx_to_md(pptx_file):
|
|
8
|
-
|
|
84
|
+
"""单文件PPT转MD:图片自动转为Base64内嵌"""
|
|
85
|
+
# 生成唯一的MD文件名和专属图片临时目录(避免多文件冲突)
|
|
86
|
+
uuid_str = IDUtil.get_uuid()
|
|
87
|
+
md_file_path = Path(tempfile.gettempdir()) / f"{uuid_str}.md"
|
|
88
|
+
temp_img_dir = Path(tempfile.gettempdir()) / f"{uuid_str}_pptx_imgs"
|
|
89
|
+
temp_img_dir.mkdir(parents=True, exist_ok=True) # 创建专属图片目录
|
|
90
|
+
|
|
91
|
+
# 配置pptx2md转换参数
|
|
9
92
|
config = pptx2md.ConversionConfig(
|
|
10
93
|
pptx_path=pptx_file,
|
|
11
94
|
output_path=md_file_path,
|
|
12
|
-
image_dir=
|
|
13
|
-
disable_notes=True
|
|
95
|
+
image_dir=temp_img_dir, # 图片导出到「专属临时目录」,而非全局临时目录
|
|
96
|
+
disable_notes=True # 根据需求调整:是否禁用PPT备注页转换
|
|
14
97
|
)
|
|
98
|
+
# 执行PPT转MD(此时MD中是图片路径,图片在临时目录)
|
|
15
99
|
pptx2md.convert(config)
|
|
100
|
+
# 核心步骤:调用替换函数,将MD中的图片路径改为Base64内嵌
|
|
101
|
+
replace_img_with_base64(md_file_path, temp_img_dir)
|
|
102
|
+
|
|
16
103
|
return md_file_path
|
|
17
104
|
|
|
105
|
+
|
|
18
106
|
def batch_pptx_to_md(input_dir: str, output_dir: str = None, image_dir: str = None):
|
|
19
107
|
"""
|
|
20
|
-
|
|
21
|
-
|
|
108
|
+
批量PPT转MD:图片自动转为Base64内嵌(原image_dir参数失效,无需传值)
|
|
22
109
|
Args:
|
|
23
110
|
input_dir (str): 包含 PPTX 文件的文件夹路径
|
|
24
111
|
output_dir (str, optional): 输出 Markdown 文件的文件夹。若为 None,则输出到与 PPTX 相同位置
|
|
25
|
-
image_dir (str, optional):
|
|
112
|
+
image_dir (str, optional): 兼容原参数,实际已失效(图片不再导出到该目录,直接内嵌Base64)
|
|
26
113
|
"""
|
|
27
114
|
input_path = Path(input_dir)
|
|
28
115
|
if not input_path.exists() or not input_path.is_dir():
|
|
29
116
|
raise ValueError(f"输入目录不存在或不是文件夹: {input_dir}")
|
|
30
117
|
|
|
31
|
-
#
|
|
118
|
+
# 处理输出目录
|
|
32
119
|
if output_dir is None:
|
|
33
120
|
output_path = input_path
|
|
34
121
|
else:
|
|
35
122
|
output_path = Path(output_dir)
|
|
36
123
|
output_path.mkdir(parents=True, exist_ok=True)
|
|
37
124
|
|
|
38
|
-
#
|
|
39
|
-
if image_dir:
|
|
40
|
-
img_path = Path(image_dir)
|
|
41
|
-
img_path.mkdir(parents=True, exist_ok=True)
|
|
42
|
-
else:
|
|
43
|
-
img_path = None
|
|
44
|
-
|
|
125
|
+
# 筛选所有pptx文件
|
|
45
126
|
pptx_files = list(input_path.glob("*.pptx"))
|
|
46
127
|
if not pptx_files:
|
|
47
128
|
print(f"在 {input_dir} 中未找到 .pptx 文件")
|
|
48
129
|
return
|
|
49
130
|
|
|
50
|
-
print(f"发现 {len(pptx_files)} 个 PPTX
|
|
131
|
+
print(f"发现 {len(pptx_files)} 个 PPTX 文件,开始转换(图片自动Base64内嵌)...\n")
|
|
51
132
|
|
|
133
|
+
# 批量转换
|
|
52
134
|
for pptx_file in pptx_files:
|
|
53
135
|
try:
|
|
54
136
|
md_file = output_path / f"{pptx_file.stem}.md"
|
|
137
|
+
# 为当前PPT创建专属临时图片目录(避免多PPT图片冲突)
|
|
138
|
+
uuid_str = IDUtil.get_uuid()
|
|
139
|
+
temp_img_dir = Path(tempfile.gettempdir()) / f"{uuid_str}_{pptx_file.stem}_imgs"
|
|
140
|
+
temp_img_dir.mkdir(parents=True, exist_ok=True)
|
|
55
141
|
|
|
142
|
+
# 配置pptx2md
|
|
56
143
|
config = pptx2md.ConversionConfig(
|
|
57
144
|
pptx_path=pptx_file,
|
|
58
145
|
output_path=md_file,
|
|
59
|
-
image_dir=
|
|
60
|
-
disable_notes=True
|
|
146
|
+
image_dir=temp_img_dir, # 图片导出到专属临时目录
|
|
147
|
+
disable_notes=True
|
|
61
148
|
)
|
|
62
149
|
|
|
63
|
-
print(f"正在转换: {pptx_file.name}
|
|
64
|
-
|
|
150
|
+
print(f"正在转换: {pptx_file.name}")
|
|
65
151
|
pptx2md.convert(config)
|
|
66
|
-
|
|
152
|
+
# 核心:替换图片路径为Base64
|
|
153
|
+
replace_img_with_base64(md_file, temp_img_dir)
|
|
154
|
+
print(f"✅ 转换成功: {md_file.name}\n")
|
|
155
|
+
|
|
67
156
|
except Exception as e:
|
|
68
|
-
print(f"❌
|
|
157
|
+
print(f"❌ 转换失败: {pptx_file.name} | 错误: {e}\n")
|
|
158
|
+
continue
|
|
69
159
|
|
|
70
|
-
print("
|
|
160
|
+
print("📌 批量转换完成!所有MD文件均为图片Base64内嵌格式")
|
|
71
161
|
|
|
72
162
|
|
|
73
163
|
if __name__ == "__main__":
|
|
74
|
-
#
|
|
75
|
-
input_folder = r'D:\测试目录_全面\ppt' #
|
|
76
|
-
output_folder = './markdown_out'
|
|
77
|
-
image_folder =
|
|
78
|
-
|
|
79
|
-
|
|
164
|
+
# 配置你的路径(image_folder无需传值,已失效)
|
|
165
|
+
input_folder = r'D:\测试目录_全面\ppt' # 你的PPT文件夹路径
|
|
166
|
+
output_folder = './markdown_out' # MD输出路径,设为None则输出到PPT同目录
|
|
167
|
+
# image_folder = None # 无需设置,图片直接Base64内嵌,该参数失效
|
|
168
|
+
|
|
169
|
+
# 执行批量转换
|
|
170
|
+
batch_pptx_to_md(
|
|
171
|
+
input_dir=input_folder,
|
|
172
|
+
output_dir=output_folder,
|
|
173
|
+
# image_dir无需传值,保留原参数仅为兼容
|
|
174
|
+
)
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: indexdoc_converter
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: 可以将Word文档(仅.docx)、Excel表格、Html网页、PPt文件 转化为Markdown文件。
|
|
5
|
+
Home-page: https://github.com/indexdoc/indexdoc-converter.git
|
|
6
|
+
Author: 杭州智予数信息技术有限公司
|
|
7
|
+
Author-email: indexdoc@qq.com
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: annotated-types==0.7.0
|
|
11
|
+
Requires-Dist: asgiref==3.11.0
|
|
12
|
+
Requires-Dist: beautifulsoup4==4.14.3
|
|
13
|
+
Requires-Dist: bottle==0.13.4
|
|
14
|
+
Requires-Dist: captcha==0.7.1
|
|
15
|
+
Requires-Dist: certifi==2026.1.4
|
|
16
|
+
Requires-Dist: cffi==2.0.0
|
|
17
|
+
Requires-Dist: chardet==5.2.0
|
|
18
|
+
Requires-Dist: charset-normalizer==3.4.4
|
|
19
|
+
Requires-Dist: clickhouse-driver==0.2.10
|
|
20
|
+
Requires-Dist: clr_loader==0.2.10
|
|
21
|
+
Requires-Dist: cobble==0.1.4
|
|
22
|
+
Requires-Dist: colorama==0.4.6
|
|
23
|
+
Requires-Dist: cryptography==46.0.3
|
|
24
|
+
Requires-Dist: cssselect==1.4.0
|
|
25
|
+
Requires-Dist: defusedxml==0.7.1
|
|
26
|
+
Requires-Dist: Django==6.0.1
|
|
27
|
+
Requires-Dist: django-ranged-response==0.2.0
|
|
28
|
+
Requires-Dist: django-simple-captcha==0.6.3
|
|
29
|
+
Requires-Dist: duckdb==1.4.3
|
|
30
|
+
Requires-Dist: et_xmlfile==2.0.0
|
|
31
|
+
Requires-Dist: filelock==3.20.3
|
|
32
|
+
Requires-Dist: fonttools==4.61.1
|
|
33
|
+
Requires-Dist: fpdf2==2.8.5
|
|
34
|
+
Requires-Dist: fsspec==2026.1.0
|
|
35
|
+
Requires-Dist: html2text==2025.4.15
|
|
36
|
+
Requires-Dist: idna==3.11
|
|
37
|
+
Requires-Dist: image==1.5.33
|
|
38
|
+
Requires-Dist: Jinja2==3.1.6
|
|
39
|
+
Requires-Dist: lxml==6.0.2
|
|
40
|
+
Requires-Dist: lxml_html_clean==0.4.3
|
|
41
|
+
Requires-Dist: mammoth==1.11.0
|
|
42
|
+
Requires-Dist: markdownify==1.2.2
|
|
43
|
+
Requires-Dist: MarkupSafe==3.0.3
|
|
44
|
+
Requires-Dist: mpmath==1.3.0
|
|
45
|
+
Requires-Dist: networkx==3.6.1
|
|
46
|
+
Requires-Dist: numpy==2.4.1
|
|
47
|
+
Requires-Dist: odfpy==1.4.1
|
|
48
|
+
Requires-Dist: openpyxl==3.1.5
|
|
49
|
+
Requires-Dist: pandas==3.0.0
|
|
50
|
+
Requires-Dist: pdfkit==1.0.0
|
|
51
|
+
Requires-Dist: pillow==12.1.0
|
|
52
|
+
Requires-Dist: pptx2md==2.0.6
|
|
53
|
+
Requires-Dist: proxy_tools==0.1.0
|
|
54
|
+
Requires-Dist: psutil==7.2.1
|
|
55
|
+
Requires-Dist: pycparser==2.23
|
|
56
|
+
Requires-Dist: pydantic==2.12.5
|
|
57
|
+
Requires-Dist: pydantic_core==2.41.5
|
|
58
|
+
Requires-Dist: PyJWT==2.10.1
|
|
59
|
+
Requires-Dist: pyperclip==1.11.0
|
|
60
|
+
Requires-Dist: python-dateutil==2.9.0.post0
|
|
61
|
+
Requires-Dist: python-docx==1.2.0
|
|
62
|
+
Requires-Dist: python-pptx==1.0.2
|
|
63
|
+
Requires-Dist: pythonnet==3.0.5
|
|
64
|
+
Requires-Dist: pytz==2025.2
|
|
65
|
+
Requires-Dist: pywebview==6.1
|
|
66
|
+
Requires-Dist: pywin32==311
|
|
67
|
+
Requires-Dist: RapidFuzz==3.14.3
|
|
68
|
+
Requires-Dist: readability-lxml==0.8.4.1
|
|
69
|
+
Requires-Dist: requests==2.32.5
|
|
70
|
+
Requires-Dist: scipy==1.17.0
|
|
71
|
+
Requires-Dist: setuptools==80.9.0
|
|
72
|
+
Requires-Dist: six==1.17.0
|
|
73
|
+
Requires-Dist: soupsieve==2.8.3
|
|
74
|
+
Requires-Dist: sqlparse==0.5.5
|
|
75
|
+
Requires-Dist: sympy==1.14.0
|
|
76
|
+
Requires-Dist: torch==2.9.1
|
|
77
|
+
Requires-Dist: tornado==6.5.4
|
|
78
|
+
Requires-Dist: tqdm==4.67.1
|
|
79
|
+
Requires-Dist: typing-inspection==0.4.2
|
|
80
|
+
Requires-Dist: typing_extensions==4.15.0
|
|
81
|
+
Requires-Dist: tzdata==2025.3
|
|
82
|
+
Requires-Dist: tzlocal==5.3.1
|
|
83
|
+
Requires-Dist: urllib3==2.6.3
|
|
84
|
+
Requires-Dist: WMI==1.5.1
|
|
85
|
+
Requires-Dist: xlsxwriter==3.2.9
|
|
86
|
+
Dynamic: author
|
|
87
|
+
Dynamic: author-email
|
|
88
|
+
Dynamic: description
|
|
89
|
+
Dynamic: description-content-type
|
|
90
|
+
Dynamic: home-page
|
|
91
|
+
Dynamic: requires-dist
|
|
92
|
+
Dynamic: requires-python
|
|
93
|
+
Dynamic: summary
|
|
94
|
+
|
|
95
|
+
<div align="center">
|
|
96
|
+
<strong>简体中文</strong> | <a href="README_EN.md">English</a>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
# indexdoc-converter 文档转换工具库
|
|
101
|
+
**indexdoc-converter** 是一款基于 Python 开发的文档转换工具库,核心功能为将主流办公文档、网页文件高效转换为 Markdown 格式。各类型文件支持格式如下:
|
|
102
|
+
- Word 文档支持 **.docx** ;
|
|
103
|
+
- Excel 类表格文档支持 **.xlsx、.xls、.ods、.csv、.tsv** ;
|
|
104
|
+
- 网页文件支持 **.html、.mhtml、.htm 及网页url** ;
|
|
105
|
+
- PPT 演示文档支持 **.pptx** 。
|
|
106
|
+
该工具库现已发布至 PyPI(Python Package Index),可通过 pip 包管理工具快速安装并投入使用。
|
|
107
|
+
|
|
108
|
+
[](https://www.python.org/) [](https://github.com/indexdoc/indexdoc-converter.git)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## 库的使用
|
|
112
|
+
```bash
|
|
113
|
+
#库安装
|
|
114
|
+
pip install -U indexdoc-converter #下载最新版本库
|
|
115
|
+
```
|
|
116
|
+
- 若使用该库 python版本最小应为 Python3.10
|
|
117
|
+
- 包目录结构
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
indexdoc-converter/ # 项目根目录
|
|
121
|
+
├── indexdoc_converter/ # 核心包目录
|
|
122
|
+
│ ├── __init__.py # 核心代码
|
|
123
|
+
│ ├── docx_to_md.py # Word转Markdown工具类
|
|
124
|
+
│ ├── excel_to_md.py # Excel转Markdown工具类
|
|
125
|
+
│ ├── html_to_md.py # Html转Markdown工具类
|
|
126
|
+
│ ├── pptx_to_md.py # ppt转Markdown工具类
|
|
127
|
+
│ └── utils/
|
|
128
|
+
│ ├── __init__.py
|
|
129
|
+
│ ├── FileUtil.py
|
|
130
|
+
│ ├── IDUtil.py
|
|
131
|
+
│ └── img_to_base64.py
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 使用示例
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
#引用 注意引用为 indexdoc_converter 而不是 indexdoc-converter
|
|
138
|
+
from indexdoc_converter.docx_to_md import convert_docx_to_md
|
|
139
|
+
from indexdoc_converter.excel_to_md import TableToMarkdown
|
|
140
|
+
from indexdoc_converter.html_to_md import convert_to_md
|
|
141
|
+
from indexdoc_converter.pptx_to_md import pptx_to_md
|
|
142
|
+
|
|
143
|
+
# -------------------------------------------Word转Markdown---------------------------------------------------
|
|
144
|
+
md_text = convert_docx_to_md(r"C:\Users\xxx\测试文档.docx", False)
|
|
145
|
+
with open('./test.md', 'w', encoding='utf-8') as f:
|
|
146
|
+
f.write(md_text)
|
|
147
|
+
|
|
148
|
+
# -------------------------------------------Excel转Markdown-------------------------------------------------
|
|
149
|
+
# 自定义参数示例
|
|
150
|
+
converter = TableToMarkdown(
|
|
151
|
+
file_title_level=2, # 文件标题的Markdown层级,默认1(#),这里设为2(##)
|
|
152
|
+
single_row_value_as_title=True, # 是否将单行唯一值识别为标题,默认True
|
|
153
|
+
max_rows=8000, # 最大处理行数,默认6000(实际处理行数是max_rows+1)
|
|
154
|
+
max_cols=200 # 最大处理列数,默认128(实际处理列数是max_cols+1)
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# 转换单个文件
|
|
158
|
+
file_path = r"C:\Users\xxx\测试文件.xlsx"
|
|
159
|
+
result = converter.convert(file_path)
|
|
160
|
+
|
|
161
|
+
# blank 模式:保留合并单元格的原始样式(只在合并单元格左上角显示内容,其余位置为空)
|
|
162
|
+
with open("../tmp/测试_blank.md", "w", encoding="utf-8") as f:
|
|
163
|
+
f.write(result['blank'])
|
|
164
|
+
|
|
165
|
+
# fill 模式:将合并单元格的内容填充到所有合并的单元格中同时还能自动识别表格中的标题行、分割多个表格块,处理空行 / 空列,兼容各种表格格式的合并单元格解析。
|
|
166
|
+
with open("../tmp/测试_fill.md", "w", encoding="utf-8") as f:
|
|
167
|
+
f.write(result['fill'])
|
|
168
|
+
|
|
169
|
+
# -------------------------------------------ppt转Markdown---------------------------------------------------
|
|
170
|
+
ppt_file = r"C:\Users\xxx\测试文件.pptx"
|
|
171
|
+
md_path = pptx_to_md(ppt_file)
|
|
172
|
+
print(f"单文件转换完成,MD文件路径:{md_path}")
|
|
173
|
+
|
|
174
|
+
# -------------------------------------------网页文件转Markdown-----------------------------------------------
|
|
175
|
+
# html = "https://news.qq.com/rain/a/20260114A01NI000"
|
|
176
|
+
html = "https://www.aituple.com"
|
|
177
|
+
# html = "https://www.indexdoc.com"
|
|
178
|
+
# html = r"C:\Users\xxx\测试文件.html"
|
|
179
|
+
# html = "https://www.indexdoc.com/contact.html"
|
|
180
|
+
md = convert_to_md(html, '../tmp/测试html.md')
|
|
181
|
+
# md = mhtml_to_markdown(mhtml)
|
|
182
|
+
```
|
|
183
|
+
### Word文档
|
|
184
|
+
#### 原文档
|
|
185
|
+

|
|
186
|
+
#### 转换后文档
|
|
187
|
+

|
|
188
|
+
|
|
189
|
+
### Excel文档
|
|
190
|
+
#### 原文档
|
|
191
|
+

|
|
192
|
+
#### 转换后文档
|
|
193
|
+

|
|
194
|
+
|
|
195
|
+
### ppt文档
|
|
196
|
+
#### 原文档
|
|
197
|
+

|
|
198
|
+
#### 转换后文档
|
|
199
|
+

|
|
200
|
+
|
|
201
|
+
### 网页文件
|
|
202
|
+
#### 原文档
|
|
203
|
+

|
|
204
|
+
#### 转换后文档
|
|
205
|
+

|
|
206
|
+
|
|
207
|
+
## 二次开发
|
|
208
|
+
|
|
209
|
+
- Python 3.10+
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
#源码地址
|
|
213
|
+
https://github.com/indexdoc/indexdoc-converter.git
|
|
214
|
+
```
|
|
215
|
+
```bash
|
|
216
|
+
#快速安装依赖库
|
|
217
|
+
pip install -r requirements.txt
|
|
218
|
+
|
|
219
|
+
# 阿里镜像源
|
|
220
|
+
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
## 📞 作者
|
|
225
|
+
|
|
226
|
+
- 作者:杭州智予数信息技术有限公司
|
|
227
|
+
|
|
228
|
+
- 邮箱:indexdoc@qq.com
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
indexdoc_converter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
indexdoc_converter/docx_to_md.py,sha256=nSMqmx8Bb-mnBtqYu1XFujJouYKYaoCh2rgusFvWhIU,2285
|
|
3
|
-
indexdoc_converter/excel_to_md.py,sha256=
|
|
4
|
-
indexdoc_converter/html_to_md.py,sha256=
|
|
5
|
-
indexdoc_converter/pptx_to_md.py,sha256=
|
|
3
|
+
indexdoc_converter/excel_to_md.py,sha256=OIGnLDVu0Lq9A_hnGa_fPAXTHiKIJOZAfqCIgwn2SwQ,27186
|
|
4
|
+
indexdoc_converter/html_to_md.py,sha256=XJ54WcU2VOtQasAEp4BqxiBhAY2uG_IVAb9-2qd_uB4,17243
|
|
5
|
+
indexdoc_converter/pptx_to_md.py,sha256=iFYrBMNNkucP3b6iJR1m8BqFmX6RZZBgqu0zj6qNFSk,7763
|
|
6
6
|
indexdoc_converter/utils/FileUtil.py,sha256=N0lTD50OkzidRpHP3ucb1EJU2Hn1q5OPxqz9iPBqEL8,1390
|
|
7
7
|
indexdoc_converter/utils/IDUtil.py,sha256=UKGbnLEkvUyMBIkfWRB8C2bZ-yvofRcKM945Z21P_dE,1018
|
|
8
8
|
indexdoc_converter/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
indexdoc_converter/utils/img_to_base64.py,sha256=KPhslxfWjze9KdKsQYqLApWWT0B4raav2Zz1MrwlziA,8287
|
|
10
|
-
indexdoc_converter-0.2.
|
|
11
|
-
indexdoc_converter-0.2.
|
|
12
|
-
indexdoc_converter-0.2.
|
|
13
|
-
indexdoc_converter-0.2.
|
|
10
|
+
indexdoc_converter-0.2.3.dist-info/METADATA,sha256=JxadWzK1jO8p_vl7ajIqpl71e7qgwoRvuXL1BrZhyHM,8650
|
|
11
|
+
indexdoc_converter-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
indexdoc_converter-0.2.3.dist-info/top_level.txt,sha256=Tqm-Q3tVPYwA5wyVSClNovUi1IwLvw6M2vlhi-WbNMs,19
|
|
13
|
+
indexdoc_converter-0.2.3.dist-info/RECORD,,
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: indexdoc_converter
|
|
3
|
-
Version: 0.2.1
|
|
4
|
-
Summary: 可以将Word文档(仅.docx)、Excel表格、Html网页、PPt文件 转化为Markdown文件。
|
|
5
|
-
Home-page: https://github.com/indexdoc/indexdoc-converter.git
|
|
6
|
-
Author: 杭州智予数信息技术有限公司
|
|
7
|
-
Author-email: indexdoc@qq.com
|
|
8
|
-
Requires-Python: >=3.10
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
Requires-Dist: annotated-types==0.7.0
|
|
11
|
-
Requires-Dist: asgiref==3.11.0
|
|
12
|
-
Requires-Dist: beautifulsoup4==4.14.3
|
|
13
|
-
Requires-Dist: bottle==0.13.4
|
|
14
|
-
Requires-Dist: captcha==0.7.1
|
|
15
|
-
Requires-Dist: certifi==2026.1.4
|
|
16
|
-
Requires-Dist: cffi==2.0.0
|
|
17
|
-
Requires-Dist: chardet==5.2.0
|
|
18
|
-
Requires-Dist: charset-normalizer==3.4.4
|
|
19
|
-
Requires-Dist: clickhouse-driver==0.2.10
|
|
20
|
-
Requires-Dist: clr_loader==0.2.10
|
|
21
|
-
Requires-Dist: cobble==0.1.4
|
|
22
|
-
Requires-Dist: colorama==0.4.6
|
|
23
|
-
Requires-Dist: cryptography==46.0.3
|
|
24
|
-
Requires-Dist: cssselect==1.4.0
|
|
25
|
-
Requires-Dist: defusedxml==0.7.1
|
|
26
|
-
Requires-Dist: Django==6.0.1
|
|
27
|
-
Requires-Dist: django-ranged-response==0.2.0
|
|
28
|
-
Requires-Dist: django-simple-captcha==0.6.3
|
|
29
|
-
Requires-Dist: duckdb==1.4.3
|
|
30
|
-
Requires-Dist: et_xmlfile==2.0.0
|
|
31
|
-
Requires-Dist: filelock==3.20.3
|
|
32
|
-
Requires-Dist: fonttools==4.61.1
|
|
33
|
-
Requires-Dist: fpdf2==2.8.5
|
|
34
|
-
Requires-Dist: fsspec==2026.1.0
|
|
35
|
-
Requires-Dist: html2text==2025.4.15
|
|
36
|
-
Requires-Dist: idna==3.11
|
|
37
|
-
Requires-Dist: image==1.5.33
|
|
38
|
-
Requires-Dist: Jinja2==3.1.6
|
|
39
|
-
Requires-Dist: lxml==6.0.2
|
|
40
|
-
Requires-Dist: lxml_html_clean==0.4.3
|
|
41
|
-
Requires-Dist: mammoth==1.11.0
|
|
42
|
-
Requires-Dist: markdownify==1.2.2
|
|
43
|
-
Requires-Dist: MarkupSafe==3.0.3
|
|
44
|
-
Requires-Dist: mpmath==1.3.0
|
|
45
|
-
Requires-Dist: networkx==3.6.1
|
|
46
|
-
Requires-Dist: numpy==2.4.1
|
|
47
|
-
Requires-Dist: odfpy==1.4.1
|
|
48
|
-
Requires-Dist: openpyxl==3.1.5
|
|
49
|
-
Requires-Dist: pandas==3.0.0
|
|
50
|
-
Requires-Dist: pdfkit==1.0.0
|
|
51
|
-
Requires-Dist: pillow==12.1.0
|
|
52
|
-
Requires-Dist: pptx2md==2.0.6
|
|
53
|
-
Requires-Dist: proxy_tools==0.1.0
|
|
54
|
-
Requires-Dist: psutil==7.2.1
|
|
55
|
-
Requires-Dist: pycparser==2.23
|
|
56
|
-
Requires-Dist: pydantic==2.12.5
|
|
57
|
-
Requires-Dist: pydantic_core==2.41.5
|
|
58
|
-
Requires-Dist: PyJWT==2.10.1
|
|
59
|
-
Requires-Dist: pyperclip==1.11.0
|
|
60
|
-
Requires-Dist: python-dateutil==2.9.0.post0
|
|
61
|
-
Requires-Dist: python-docx==1.2.0
|
|
62
|
-
Requires-Dist: python-pptx==1.0.2
|
|
63
|
-
Requires-Dist: pythonnet==3.0.5
|
|
64
|
-
Requires-Dist: pytz==2025.2
|
|
65
|
-
Requires-Dist: pywebview==6.1
|
|
66
|
-
Requires-Dist: pywin32==311
|
|
67
|
-
Requires-Dist: RapidFuzz==3.14.3
|
|
68
|
-
Requires-Dist: readability-lxml==0.8.4.1
|
|
69
|
-
Requires-Dist: requests==2.32.5
|
|
70
|
-
Requires-Dist: scipy==1.17.0
|
|
71
|
-
Requires-Dist: setuptools==80.9.0
|
|
72
|
-
Requires-Dist: six==1.17.0
|
|
73
|
-
Requires-Dist: soupsieve==2.8.3
|
|
74
|
-
Requires-Dist: sqlparse==0.5.5
|
|
75
|
-
Requires-Dist: sympy==1.14.0
|
|
76
|
-
Requires-Dist: torch==2.9.1
|
|
77
|
-
Requires-Dist: tornado==6.5.4
|
|
78
|
-
Requires-Dist: tqdm==4.67.1
|
|
79
|
-
Requires-Dist: typing-inspection==0.4.2
|
|
80
|
-
Requires-Dist: typing_extensions==4.15.0
|
|
81
|
-
Requires-Dist: tzdata==2025.3
|
|
82
|
-
Requires-Dist: tzlocal==5.3.1
|
|
83
|
-
Requires-Dist: urllib3==2.6.3
|
|
84
|
-
Requires-Dist: WMI==1.5.1
|
|
85
|
-
Requires-Dist: xlsxwriter==3.2.9
|
|
86
|
-
Dynamic: author
|
|
87
|
-
Dynamic: author-email
|
|
88
|
-
Dynamic: description-content-type
|
|
89
|
-
Dynamic: home-page
|
|
90
|
-
Dynamic: requires-dist
|
|
91
|
-
Dynamic: requires-python
|
|
92
|
-
Dynamic: summary
|
|
File without changes
|
|
File without changes
|