Pandoc: applying a style to all images when exporting to docx?

Viewed 332

I used to ask this question a few years ago, and back then it was not possible to apply a style to all images when exporting to docx using Pandoc.

Today, I wonder whether this still is true? I tried a bit using Pandoc 2.9.x, and images still seem to have applied the generic "Normal" style:

screenshot

It would be nice to have a style like "Picture" which is applied to each image in the docx. Any way to do this?

1 Answers

Images by themselves cannot have any style, you have to wrap an image into a block, that can have custom attributes. I replace figure elements with a pair of an image and a caption, something like this:

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
Related