【问题标题】:How to retain HTML styles after conversion to docx with Pandoc使用 Pandoc 转换为 docx 后如何保留 HTML 样式
【发布时间】:2018-01-02 00:56:34
【问题描述】:

我有一个像这样的 html 文件:

<!DOCTYPE html>
<html>
<head>
<style>
h1 {text-align:center;}
p {text-align:center;}
</style>
</head>
<body>

<h1>My heading</h1>
<p>Some poetry here.</p>

</body>
</html>

我想将它转换为 pandoc 中的 docx。我尝试使用通常的命令

pandoc -s test.html -o test.docx

并且文本被正确渲染,但它没有居中。我会自动生成数百个 html,因此手动修复不在预算之内。基本上我需要一些段落左对齐(默认)和一些居中,因为它们是诗歌。如何实现?

谢谢。

PS:我也可以使用 markdown 作为输入语言而不是 Html。

【问题讨论】:

  • pandoc 不处理样式。

标签: pandoc


【解决方案1】:

您需要自定义一个 docx 模板,并在将 HTML 转换为 docx 时应用该模板。在您的情况下,&lt;h1&gt; 在 Word 中被转换为 Heading 1&lt;p&gt; 被转换为 First Paragraph

步骤:

  1. 创建一个 docx 模板。

    pandoc -o custom-reference.docx --print-default-data-file reference.docx

  2. 打开custom-reference.docx并修改样式。

    1. 中心Heading 1
    2. 中心First Paragraph
  3. 保存custom-reference.docx

  4. 转换。

    pandoc input.html -o output.docx --reference-doc custom-reference.docx

【讨论】:

    猜你喜欢
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多