首页 > 其他分享 >Word docx转html和markdown

Word docx转html和markdown

时间:2023-10-29 16:39:03浏览次数:29  
标签:md convert markdown pypandoc docx somefile html file


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

安装

# 不带pandoc执行库
pip install pypandoc

# 自带pandoc
pip install pypandoc_binary

使用

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

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/


标签:md,convert,markdown,pypandoc,docx,somefile,html,file
From: https://blog.51cto.com/lilongsy/8080489

相关文章

  • 基于jquery+html开发的json格式校验工具
    json简介JSON是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。它基于JavaScriptProgrammingLanguage,StandardECMA-2623rdEdition-December1999的一个子集。JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C,C++,......
  • 基于jquery+html开发的json格式校验工具
    json简介JSON是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。它基于JavaScriptProgrammingLanguage,StandardECMA-2623rdEdition-December1999的一个子集。JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C,C++......
  • ERROR: Cannot unpack file C:\Users\17482\AppData\Local\Temp\pip-unpack-9g9
    ERROR:CannotunpackfileC:\Users\17482\AppData\Local\Temp\pip-unpack-9g93t3zt\simple.html(downloadedfromC:\Users\17482\AppData\Local\Temp\pip-req-build-35ukmesa,content-type:text/html);cannotdetectarchiveformatERROR:Cannotdeterm......
  • referencing included files in pandoc markdown for docx output
    IhavemultiplemarkdownfilestobecomeaWorddoc:pandoc-fmarkdown--toc-oout.docxfile1.mddirA\file2.mddirB\file3.mdIfyouspecifymultipleinputfiles,theyareactuallyconcatenatedbytheshellandthenpassedtopandoc.Sono,theinpu......
  • 用html 加css 绘制表格
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Title</title><style>/*头部样式定义*/.header{padding-bottom:10px;/*设置头部的下内边距*/......
  • HTML基础内容之表单
    HTML表单 HTML表单是用于收集用户输入的信息,并将用户输入的内容信息传到后台服务器中。HTML表单的action属性表单中action属性,里面填写的是后台服务器的地址。比如:1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8">5<metaname="vie......
  • vs code markdown mermaid预览插件安装
    安装预览插件预览指令使用control+shift+p效果......
  • html 隐藏元素占位/不占位
    关于循环定时隐藏/显示元素,从而实现一个一闪一闪的效果如图:实现方法:设置display但是display在设为none是不占位置隐藏的display:none;设置visibility而visiblity是占位隐藏visibility:hidden;varnum=true;window.setInterval(()=>{vari=document.......
  • PCB封装命名规则,本文转载https://www.xjx100.cn/news/432127.html?action=onClick
    SO、SOP、SOIC、MSOP、TSSOP、TSOP、VSSOP、SSOP、SOJ封装详解 1. 简要信息如下: 2.SOP和SOIC的规格多是类似的,现在大多数厂商基本都采用的是SOIC的描述:SOIC8有窄体150mil的(外形封装宽度,不含管脚,下同),管脚间距是1.27mm,如下:有宽体的208mil的,管脚间距是1.27mm,如下:......
  • FastAPI学习-17.其它响应html,文件,视频或其它
    前言通过我们返回JSON类型的接口会比较多,除了返回JSON格式,还可以响应其它格式的内容JSONResponseContent-Type 会被设置成 application/jsonHTMLResponseContent-Type 会被设置成 text/htmlPlainTextResponse Content-Type 会被设置成text/plainORJSONResponse......