md2star.postprocess module
postprocess.py — Re-inject Pandoc-stripped styles into the output DOCX.
Pandoc’s DOCX writer reads the reference template’s word/styles.xml but
rewrites it from its own catalogue on output. Paragraph and character styles
defined in the reference that Pandoc happens to use survive; arbitrary
custom-styled table styles do not — Pandoc drops them, leaving the
<w:tblStyle w:val="X"/> references in the body pointing at nothing.
This module reopens the produced .docx zip, locates word/styles.xml,
and inserts the MyTable and MyTableSmall table styles (thin gray
#9E9E9E borders; the small variant also forces an 8 pt font + tighter
cell margins). It is idempotent: existing definitions are left untouched.
The XML is parsed with xml.etree.ElementTree rather than mutated as
a string, so trailing whitespace, attribute ordering, or namespace prefix
differences cannot break the rewrite.
Invoked by the md2docx CLI immediately after Pandoc finishes.
- md2star.postprocess.inject_table_styles(docx_path)[source]
Inject MyTable + MyTableSmall into docx_path’s
word/styles.xml.Returns True if any style was added, False if both were already present (or if the styles.xml could not be parsed — defensive no-op).
- md2star.postprocess.strip_table_normal_for_pdf(docx_path)[source]
Neutralize the bundled template’s
TableNormal0in docx_path.Word renders the style fine; LibreOffice headless does not. We call this on the intermediate DOCX produced inside the
md2pdfpipeline so the soffice render is correct. The user’s DOCX output (when they callmd2docx) is untouched.Returns True if any mutation happened, False otherwise.