Compiling via Pandoc to .docx - changing table format

As Pandoc + Scrivener are so flexible, there are multiple places[1] you can make modifications:

  1. Use custom styles (Pandoc - Pandoc User’s Guide) and a reference document (simplest way to get specific styling).
  2. Use Compiler regex replacements with some unique editor tags.
  3. Manually injecting XML with Compiler prefix/suffix/formats, as you are doing automatically, in the .md using Scrivener.
  4. Manually injecting the XML, using a post-processing script run after Scrivener generates the markdown, but before Pandoc is called. This may give you a bit more control…
  5. Pandoc filter: this takes an abstract document and provides quite precise targeting of elements. Pandoc forum is good for getting help with filters.
  6. Custom Pandoc writer (hard!)
  7. Using a script to edit the XML in the final DOCX zip (like python-docx — python-docx 1.1.2 documentation).

Have you had tried to use custom styles, as that is much simpler (though how easy it is to trigger Word’s table styling I don’t know, I know table styles are not easy to work with). It may help to make a small sample markdown file of a minimal table, and try with pandoc directly to simplify the task before using Scrivener to bake in a final solution.

If I had your task, I would try the custom styles first, then Lua filter, then prefix/suffix or replacements, then scripting.

As an aside, I have a Pandoc filter for indexing: Making an index? - #32 by nontroppo – this demonstrates syntax injection using a filter and works across multiple outputs so is more flexible than manual XML injection in Scrivener…

By the way, ODT XML is much easier to work with in general than DOCX XML, and using LibreOffice instead of Word to generate the final DOCX may make some of the steps a bit easier…


[1] I use pandocomatic precisely because it gives me lots of control in running extra tools at every stage of the pandoc process, keeping all steps in a single recipe.

5 Likes