Search code examples
filterluapandoc

pandoc lua filter to apply Quotations style to a Div when converting to docx


I'm using pandoc to convert from latex to docx. In the pandoc AST, the latex \quoting environment is represented by a Div, like this:

, Div
    ( "" , [ "quoting" ] , [] )
    [ Para
        [ Str
            "\26377\38065\23601\20986"
        ]
    ]

However, this is ignored when writing out the docx file. How do I use a lua filter to apply the Quotations style that's already defined in the reference docx file to the contents of this Div? I have read all the documentation but still lack the necessary info and skill to write the filter myself. Any help will be greatly appreciated.


Solution

  • The docx writer will use a style if it's passed via the custom-style attribute. So a filter like this should work:

    function Div (div)
      if div.classes:includes 'quoting' then
        div.attributes['custom-style'] = 'Quotations'
        return div
      end
    end