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/

相关推荐
BruceGerGer9 天前
flutter开发实战-flutter web加载html及HtmlElementView的使用
flutter·1024程序员节
网络冒险家2 个月前
【软考】系统集成项目管理工程师【第二版】
职场和发展·软考·集成学习·1024程序员节·系统集成项目工程师
BruceGerGer2 个月前
flutter开发实战-AssetBundle读取指定packagename的文件
flutter·1024程序员节
sheng12345678rui2 个月前
最新缺失msvcp140.dll的多种解决方法,有效解决电脑dll问题
windows·microsoft·电脑·dll文件·1024程序员节
a5553338202 个月前
电脑显示mfc140u.dll丢失的修复方法,总结7种有效的方法
java·经验分享·dll·dll文件丢失·1024程序员节
行十万里人生2 个月前
C++ 智能指针
linux·c++·git·阿里云·容器·蓝桥杯·1024程序员节
a5553338202 个月前
启动鸣潮提示错误代码126:加载d3dcompiler_43.dll错误或缺失的7个解决方法
前端·经验分享·dll·dll文件丢失·1024程序员节
BruceGerGer2 个月前
flutter开发实战-Webview及dispose关闭背景音
flutter·1024程序员节
BruceGerGer3 个月前
flutter开发实战-ListWheelScrollView与自定义TimePicker时间选择器
flutter·1024程序员节
askah66443 个月前
电脑提示msvcr120.dll丢失怎样修复
经验分享·microsoft·dll修复·dll丢失·1024程序员节