GrepBoard/Manuals
605 manuals ·

Convert a Word docx to Markdown for AI input with pandoc

·Tested on Ubuntu 24.04 · pandoc 3.1.3 · 2026-10·Test scope ↓·7 steps

Convert a docx with tables, footnotes and tracked changes to Markdown with pandoc, see what breaks, and what to watch for converting the AI-edited file back.

Convert a docx with tables, footnotes, tracked changes and comments to Markdown with pandoc, check what disappears, then turn the AI-edited Markdown back into docx. For checking an AI proofreading pass, see Get proofreading results as a change table.

[1] The test file report.docx has a Title, headings, bold/italic, a hyperlink, a bullet list, a footnote, a table (with a vertical and a horizontal merge), a table caption, tracked changes (one deletion, one insertion), one comment and one equation. Convert it to GFM with no other options. --wrap=none stops pandoc from folding paragraphs at 72 columns.

console
$ pandoc --version | head -1pandoc 3.1.3$ pandoc report.docx -t gfm --wrap=none -o report.md$ cat report.md# 1. Summary Revenue grew **12%** over the previous quarter[^1]. See the [pandoc manual](https://pandoc.org/MANUAL.html). The *main driver* was new customers. - First item - Second item # 2. Figures |                       |        |        ||-----------------------|--------|--------|| **Region**            | **Q2** | **Q3** || North                 | 120    | 135    ||                       | 130    | 141    || Total (merged across) |        |        | Table 1. Sales by region # 3. Review The contract renews yearly and a new clause. Check this figure. Text with a comment. Formula: $x = y + 1$ [^1]: Excludes returns, per finance team.

Formatting, links, lists, the footnote and the equation come through.

[2] What broke:

ElementDefault resultFix
Document title (Title style)Gone-s (step 3)
Table header rowAn empty header row is added; the real header row drops into the bodyMark the header row (step 4)
Merged cellsMerge is lost, empty cells remainHTML table (step 5)
Table captionPlain paragraph below the tableLeave it
Tracked changesInsertions applied, deletions dropped--track-changes (step 6)
CommentsGone--track-changes=all (step 6)

[3] Add -s (standalone) to get the title as a YAML header.

console
$ pandoc report.docx -s -t gfm --wrap=none | head -4---title: Quarterly Report---

[4] A row becomes the Markdown header row only if the docx marks it as a header (w:tblHeader). After marking just the first row in the test file, the empty line is gone.

console
$ pandoc report-h.docx -t gfm --wrap=none | sed -n '3,6p'| **Region**            | **Q2** | **Q3** ||-----------------------|--------|--------|| North                 | 120    | 135    ||                       | 130    | 141    |

[5] GFM cannot express merged cells. Convert the same file with -t html and rowspan/colspan survive.

console
$ pandoc report.docx -t html | grep -E 'rowspan|colspan'<td rowspan="2">North</td><td colspan="3">Total (merged across)</td>

Before handing such a table to an AI, keep only that table as HTML, or unmerge it and fill in the values first.

[6] The default is --track-changes=accept: deletions vanish and insertions become body text, as in the first output. Use all to keep the reviewer and date.

console
$ pandoc report.docx -t gfm --wrap=none --track-changes=all -o report-all.md$ sed -n '/# 3/,/^<span class="comment/p' report-all.md# 3. Review <span class="deletion" author="Reviewer A" date="2026-10-19T09:00:00Z">old wording</span> The contract renews yearly <span class="insertion" author="Reviewer A" date="2026-10-19T09:00:00Z">and a new clause</span>. <span class="comment-start" id="0" author="Reviewer B" date="2026-10-19T10:00:00Z">Is this the final number?</span>Check this figure<span class="comment-end" id="0"></span>. Text with a comment.

all also brings the comments. With reject the deleted wording comes back and the insertion is dropped; the reject output for this file starts with old wording The contract renews yearly.

[7] Check the round trip. Pretend the AI edited the file: change 12% to 14% in report-all.md (saved with all in step 6), then convert back. Reading with markdown turns the spans back into Word tracked changes and comments.

console
$ sed 's/12%/14%/' report-all.md > edited.md$ pandoc edited.md -f markdown -o back.docx$ unzip -p back.docx word/document.xml | grep -o '<w:ins \|<w:del \|commentReference\|footnoteReference' | sort | uniq -c      1 <w:del       1 <w:ins       1 commentReference      1 footnoteReference

Reading the same file with -f gfm loses the tracked changes and the comment. The same check showed only the footnoteReference line, and the deleted text old wording and the comment text entered the body as ordinary text. Round-tripping the default report.md from step 1 gives the same single footnoteReference even with -f markdown: only a file saved with all keeps the tracked changes. If the document's tracked changes must survive, convert back with -f markdown only.

#pandoc#docx#markdown#claude