Word docx转html和markdown

Pypandoc使用pandoc来进行各种文本格式的转换。

安装

python 复制代码
# 不带pandoc执行库
pip install pypandoc

# 自带pandoc
pip install pypandoc_binary

使用

python 复制代码
import pypandoc

# convert all markdown files in a chapters/ subdirectory.
pypandoc.convert_file('chapters/*.md', 'docx', outputfile="somefile.docx")

# convert all markdown files in the book1 and book2 directories.
pypandoc.convert_file(['book1/*.md', 'book2/*.md'], 'docx', outputfile="somefile.docx")

# convert the front from another drive, and all markdown files in the chapter directory.
pypandoc.convert_file(['D:/book_front.md', 'book2/*.md'], 'docx', outputfile="somefile.docx")

支持pathlib

python 复制代码
import pypandoc
from pathlib import Path

# single file
input = Path('somefile.md')
output = input.with_suffix('.docx')
pypandoc.convert_file(input, 'docx', outputfile=output)

# convert all markdown files in a chapters/ subdirectory.
pypandoc.convert_file(Path('chapters').glob('*.md'), 'docx', outputfile="somefile.docx")

# convert all markdown files in the book1 and book2 directories.
pypandoc.convert_file([*Path('book1').glob('*.md'), *Path('book2').glob('*.md')], 'docx', outputfile="somefile.docx")
# pathlib globs must be unpacked if they are inside lists.

参考

https://pypi.org/project/pypandoc/

https://pandoc.org/help.html

https://www.strerr.com/cn/word2html.html

https://zhuanlan.zhihu.com/p/30891168

https://pypi.org/project/pandoc/

相关推荐
u01030552718 小时前
AI驱动的安卓UI自动生成功能实现
人工智能·1024程序员节
u0103055271 天前
长株潭智能体赋能腾讯元器链接共享
1024程序员节
云贝贝贝3 天前
OceanBase认证体系介绍与备考指南
运维·服务器·oceanbase·1024程序员节
u0103055273 天前
Java图像处理实战指南
人工智能·1024程序员节
u0103055273 天前
Java AWT鼠标事件全解析
人工智能·1024程序员节
u0103055276 天前
Java实用类应用精讲
人工智能·1024程序员节
u0103055276 天前
Java I/O核心操作实战
人工智能·1024程序员节
u0103055277 天前
ArrayList操作详解与实战应用
人工智能·1024程序员节
u0103055278 天前
Java模块化编程实战指南
人工智能·笔记·1024程序员节
u0103055279 天前
使用BufferedReader读取控制台输入
人工智能·1024程序员节