Markdown到docx,包括复杂模板 [英] Markdown to docx, including complex template
问题描述
我已经使构建自动化,可以使用Pandoc将Markdown文件转换为DOCX文件.我甚至在最终文档的样式中都使用了参考文档.我使用的命令是:
I have automated my build to convert Markdown files to DOCX files using Pandoc. I have even used a reference document for the final document's styling. The command I use is:
pandoc -f markdown -t docx --data-dir=docs/rendering/ mydoc.md -o mydoc.docx
Panddoc从docs/rendering
中拾取reference.docx
,并且Pandoc渲染mydoc.docx
的样式与参考文档相同.
The reference.docx
is picked up by Pandoc from docs/rendering
and Pandoc renders mydoc.docx
with the same styles as the reference doc.
但是,reference.docx
不仅包含样式.它包含公司徽标,序言等.
However, reference.docx
contains more than just styles. It contains coporate logos, preamble, etc.
如何自动将Markdown内容与reference.docx
的样式和内容合并.我的解决方案需要在Linux上运行.
How can I automate the merging of the Markdown content with both the styles and content of reference.docx
. My solution needs to work on Linux.
推荐答案
更新
使用克里斯蒂安·朗(Christian Long)用户建议的管道版本:
Use the piped version suggested by user Christian Long:
pandoc -t latex mydoc.md | pandoc -f latex --data-dir=docs/rendering/ -o mydoc.docx
我知道这来得太晚了,但我可以假设人们在最初提出问题的三年后仍在寻找解决方案-我知道我是.
I know this is late in coming, but I'll be assuming people are still searching for solutions to this three years after the original question -- I know I was.
我的解决方案是使用LaTeX作为markdown和docx之间的中介(实际上,我是从org-mode转换的,但有相同的区别).因此,在您的情况下,我相信一种解决方案是:
My solution was to use LaTeX as an intermediary between markdown and docx (actually, I was converting from org-mode, but same difference). So in your case, I believe a one-liner solution would be:
pandoc -f markdown -t latex -o mydoc.tex mydoc.md && \
pandoc -f latex -t docx --data-dir=docs/rendering/ -o mydoc.docx mydoc.tex
这可能使您更接近目标.当然,Pandoc可以处理大约一百个参数,并且可能有一些方法可以使它更漂亮.自您首次发布问题以来,它也获得了相当多的更新.
Which might get you closer to your goal. Of course, Pandoc has about hundred arguments it can handle, and there are probably ways to make this prettier. It has also gotten quite a few updates since you first posted your question.
这篇关于Markdown到docx,包括复杂模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!