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/

相关推荐
✿ ༺ ོIT技术༻6 天前
Linux:TCP和守护进程
linux·运维·服务器·网络·tcp/ip·1024程序员节
辅助东皇燕双鹰10 天前
行测知识()
1024程序员节
深蓝易网13 天前
探寻制造型企业MES管理系统:功能、架构与应用全解析
大数据·运维·人工智能·架构·制造·1024程序员节
Lenyiin18 天前
2848、与车相交的点
c++·算法·leetcode·1024程序员节
earthzhang202123 天前
《深入浅出HTTPS》读书笔记(31):HTTPS和TLS/SSL
开发语言·网络·python·https·1024程序员节
不讲废话的小白25 天前
怎么样把pdf转成图片模式(不能复制文字)
pdf·1024程序员节
明明真系叻1 个月前
2025.1.26机器学习笔记:C-RNN-GAN文献阅读
人工智能·笔记·深度学习·机器学习·生成对抗网络·1024程序员节
Joeysoda1 个月前
Java数据结构 (从0构建链表(LinkedList))
java·linux·开发语言·数据结构·windows·链表·1024程序员节
清风-云烟1 个月前
使用redis-cli命令实现redis crud操作
java·linux·数据库·redis·spring·缓存·1024程序员节
Joeysoda1 个月前
Java数据结构 (链表反转(LinkedList----Leetcode206))
java·linux·开发语言·数据结构·链表·1024程序员节