【问题标题】:Pandoc: applying a style to all images when exporting to docx?Pandoc:导出到 docx 时将样式应用于所有图像?
【发布时间】:2020-06-02 13:47:53
【问题描述】:

几年前我曾经问过这个问题,当时使用 Pandoc 导出到 docx 时无法将样式应用于所有图像。

今天,我想知道这是否仍然是真的?我使用 Pandoc 2.9.x 尝试了一下,图像似乎仍然应用了通用的“Normal”样式:

最好有一个像“图片”这样的样式应用于 docx 中的每个图像。有什么办法吗?

【问题讨论】:

  • 我对docx格式不是很了解,但是你见过pandoc.org/MANUAL.html#custom-styles吗?或许你也可以编写一个 lua-filter 来为所有图片添加 custom-style 属性...
  • 这看起来很有希望!我可以在格式化降价代码时添加这样的样式,然后再将其导出到 docx。这不是最优雅的选择(例如 CSS'img { ... }),但我猜它会起作用。谢谢!
  • 好吧,或者只是写一个filter 来转换文档AST...应该不那么脆弱...

标签: image ms-word formatting pandoc


【解决方案1】:

图像本身不能有任何样式,您必须将图像包装成一个可以具有自定义属性的块。我用一对图像和一个标题替换图形元素,如下所示:

funFigure = function(element)
    local attrfigure = pandoc.Attr( "", { }, {{"custom-style", "Picture" }} )
    local attrfiguretext = pandoc.Attr( "", { }, {{"custom-style", "Picture Caption" }} )
    local figuretext = pandoc.Div(pandoc.Para(element.content[1].caption), attrfiguretext)
    element.content[1].caption = pandoc.Null
    local figure = pandoc.Div(element, attrfigure)
    return { figure, figuretext }
end

【讨论】:

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