【发布时间】:2017-12-15 04:55:46
【问题描述】:
我有一个带有figure、img 和figcaption 标签的 HTML,我希望将它们转换为 Microsoft Word 文档。
img 引用的图片应插入 Word 文档中,figcaption 应转换为其标题(同样保留图号)。
我尝试使用 Word 2013 打开 html,但 figcaption 没有转换为图片标题,它只是图片下方的简单文本。
是否有任何最低限度的工作样本来完成它?我查看了https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Word_XML_Format_example,但它太冗长,无法仅获取 Hello world 示例。
figure .image {
width: 100%;
}
figure {
text-align: center;
display: table;
max-width: 30%; /* demo; set some amount (px or %) if you can */
margin: 10px auto; /* not needed unless you want centered */
}
article {
counter-reset: figures;
}
figure {
counter-increment: figures;
}
figcaption:before {
content: "Fig. " counter(figures) " - "; /* For I18n support; use data-counter-string. */
}
<figure>
<p><img class="image" src="https://upload.wikimedia.org/wikipedia/commons/c/ca/Matterhorn002.jpg"></p>
<figcaption>Il monte Cervino.</figcaption>
</figure>
<figure>
<p><img class="image" src="https://upload.wikimedia.org/wikipedia/commons/2/26/Banner_clouds.jpg"></p>
<figcaption>La nuvola che spesso è vicino alla vetta.</figcaption>
</figure>
我尝试在 Windows 上使用 pandoc
pandoc -f html -t docx -o hello.docx hello.html
但是没有运气,你可以看到“图 1”和“图 2”不见了:
我的 pandoc 是:
c:\temp>.\pandoc.exe -v
pandoc.exe 1.19.2.1
Compiled with pandoc-types 1.17.0.4, texmath 0.9, skylighting 0.1.1.4
Default user data directory: C:\Users\ale\AppData\Roaming\pandoc
Copyright (C) 2006-2016 John MacFarlane
Web: http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
编辑 1
也可以使用一些 C# 来完成它。也许我可以通过 C# 程序将 HTML 转换为某种 XML Word 格式。
【问题讨论】:
-
你试过最新的pandoc版本了吗?
-
@mb21 我用我认为是最新的 pandoc 1.19.2.1 对其进行了测试。
-
这很奇怪,我刚刚在 Linux 上尝试过,它会下载图像并将它们嵌入到 word 文件中(使用 libreoffice 打开)。所以也许是窗户的东西......
-
@mb21 标题正确吗?我的意思是自动数字编号。
标签: c# html css ms-word pandoc