Search code examples
filterluapandoc

pandoc lua filter to apply Emphasis character style to Emph elements when converting to docx


I'm using pandoc to convert from latex to docx. In the pandoc AST, emphasized text is marked with "Emph", like this:

, Emph [ Str "Variety" ]

and is rendered as italics when writing out to the docx file. I would like to use a lua filter to apply Emphasis character style defined in the reference docx file to such text. 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

  • This can be done by changing the Emph into a Span with a custom-style attribute:

    function Emph (emph)
      return pandoc.Span(emph.content, {['custom-style'] = 'Emphasis'})
    end