Formats

Converting Word documents (DOCX) to Markdown with MarkItDown

Updated 2026-11-15·Upstream source ↗
Markdown view

Word is where MarkItDown is strongest, because a DOCX file really does contain headings, lists and tables. We built one test file per feature, converted each with version 0.1.9 and judged the result against the Markdown it should have produced: of 35 Word features, 19 were kept, 13 changed and 3 lost (one more row is the legacy .doc case).

Short answer

Install the extra, convert, save with -o:

Command
pip install "markitdown[pdf]"
Command
markitdown report.docx -o report.md

(Use docx instead of pdf in the first command.) Headings, emphasis, lists, links and tables come through. Check table header rows, cells that contain |, the document title, nested bullets and images.

Tested with markitdown 0.1.9 · Python 3.13 · markitdown[all] 0.1.9 · Linux lab; the DOCX corpus also ran on Windows, macOS and Ubuntu runners (T03, T05) · LibreOffice 24.2, Pandoc 3.1 for building test files · 2026-11-15 · evidence: office-features.csv, format-matrix.csv, docx-features.jsonl

Feature by feature: kept, changed, lost

Kept means the Markdown matches what the feature should produce; changed means it survives but differently; lost means it is not in the output.

35 Word features, one test file each, markitdown 0.1.9
FeatureResultWhat came outNote
Title and Subtitle styleslostThe Document Title↵↵A subtitle line↵↵# First section↵↵Body text.Title is a paragraph style, not a heading. missing: ['# The Document Title']
Heading levels 1 to 6kept# Heading level 1↵↵## Heading level 2↵↵### Heading level 3↵↵#### Heading level 4↵↵##### Heading level 5↵↵###### Heading level 6
Bold, italic, underline, strikekept**bold** *italic* <u>underlined</u> ~~struck~~ x2 H2Underline and strike come out as HTML-style or Markdown markers; see the excerpt.
Underline, strike, superscript, subscriptchanged**bold** *italic* <u>underlined</u> ~~struck~~ x2 H2Underline becomes <u>…</u>, strike becomes ~~…~~; check superscript and subscript in the excerpt: kept as plain digits
HyperlinkkeptSee [the example page](https://example.org/page) for details.
Nested bullets by paragraph stylechanged* Top one↵* Second level↵* Third level↵* Top twoCompare the indentation of the three levels. missing: [' * Second level', ' * Third level']
Numbered list by paragraph stylechanged1. First↵2. Second↵3. Nested number↵4. Thirdmissing: ['3. Third']
Nested bullets with list levelskept* Top one↵ + Second level↵ - Third level↵* Top twoReal list levels survive; the bullet character alternates (* + -).
Numbered list with list levelskept1. First↵ 1. Nested↵2. Second↵3. Third
Table with a marked header rowkept| Station | Rainfall | Notes |↵| --- | --- | --- |↵| Alpha | 412.5 | ok |↵| Bravo | 388.0 | low |Check whether the first line of the table is the header or an empty row.
Table without a header-row flagchanged| | | |↵| --- | --- | --- |↵| Station | Rainfall | Notes |↵| Alpha | 412.5 | ok |↵| Bravo | 388.0 | low |The flag set in Word (Table Design, Header Row, Repeat as header) decides whether the header is real. the table starts with an empty header row; the real first row is the second line.
Title style mapped to a headingkept# The Document Title↵↵A subtitle line↵↵# First section↵↵Body text.style_map is a constructor argument.
Subtitle style mapped to a second-level headingkept# The Document Title↵↵## A subtitle line↵↵# First section↵↵Body text.
Merged cellschanged| | | |↵| --- | --- | --- |↵| Merged title across three columns | | |↵| A | B | C |↵| 1 | 2 | 3 |the table starts with an empty header row; the real first row is the second line.
A pipe character inside a cellchanged| | |↵| --- | --- |↵| Key | Value |↵| state | OK | stable |An unescaped | adds a column. the pipe is not escaped, so the row gets an extra cell
Pipe workaround: escape the pipe in the file firstchanged| | |↵| --- | --- |↵| Key | Value |↵| state | OK \| stable |Edits the DOCX XML (script in the page); the document shown to the reader is unchanged. the table starts with an empty header row; the real first row is the second line.
Multi-paragraph cellchanged| | |↵| --- | --- |↵| Name | Details |↵| Alpha | first paragraph second paragraph |the table starts with an empty header row; the real first row is the second line.
Nested tablechanged| | | | | | |↵| --- | --- | --- | --- | --- | --- |↵| outer left | | | | | --- | --- | | in1 | in2 | | in3 | in4 | |the table starts with an empty header row; the real first row is the second line.
Wide table (12 columns)changed| | | | | | | | | | | | |↵| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |↵| H1 | H2 | H3 | H4 | H5 | H6 | H7 | Hthe table starts with an empty header row; the real first row is the second line.
Embedded picture, no alt textkept![](data:image/png;base64...)↵↵AfterBy default the image data is cut off; see keep_data_uris.
Embedded picture with alt textkept![A bar chart of quarterly revenue](data:image/png;base64...)The alt text is used as the Markdown alt text.
keep_data_uris on a picturekeptBefore↵↵![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAFoCAIAAABIUN0GAAAgmUlEQVR4nO3dd1yV5f/H8QsPIgii4gAHigriwJl7pObELe7ZMCvN3KY2rF+WWZm5MsscOutput grows from 44 to 11246 characters.
Page breakkeptPage one text↵↵Page two text
Header and footer textlostPage one text↵↵Page two textHeaders and footers are not read. missing: ['Running header text', 'Running footer text']
CommentslostText with a comment attached.Comments are not part of the main document text. missing: ['This is the reviewer comment.']
Tracked changes (insertion and deletion)keptKept text inserted wordsDeleted text should not appear.
Custom styles without a mappingkeptprint('hello')↵↵A key phrase inside text.Unmapped custom styles come out as ordinary text.
Custom paragraph style mapped to codekeptprint('hello')↵```↵↵A key phrase inside text.
Custom character style mapped to emphasiskeptA *key phrase* inside text.
FootnoteschangedA sentence with a note.[[1]](#footnote-20)↵↵1. The footnote text itself. [↑](#footnote-ref-20)Footnote text is in a separate part of the file. the reference becomes a link to #footnote-N and the note text is a numbered list at the end
Table of contentskept# One↵↵text↵↵# Two↵↵text↵↵## Two point one↵↵text
EquationkeptInline $x^{2}+y^{2}=z^{2}$ and display:↵↵$$\frac{a}{b}=c$$Equations are converted to LaTeX when markitdown can read the Office Math.
Block quote and code blockchangedA quoted line.↵↵code line one↵code line twoCode blocks have no fence; check the excerpt. missing: ['> A quoted line.']
Right-to-left textkeptمرحبا بالعالم עברית
Document written by LibreOfficechanged# LO Title↵↵* one↵ + two↵ - three↵↵1. a↵2. b↵↵| | |↵| --- | --- |↵| H | V |↵| 1 | 2 |The 'w:ilvl' KeyError reported upstream concerns non-Word writers; we record what this file does. the table starts with an empty header row; the real first row is the second line.
35 Word features, one test file each, markitdown 0.1.9 Source: Test T07 · Linux lab · 2026-11-15 · office-features.csv · Download CSV

See it on a document

The synthetic report from the quickstart, with each part of the output tied to the region it came from:

5 headings → 4 kept, 1 changed · 1 paragraph → 1 kept · 2 lists → 2 kept · 1 table → 1 kept

Input · report.docx

Page image of report.docx, the input document

Output · markitdown report.docx

Pilot Report: Field Station Alpha
 
# 1. Summary
 
This report covers **three sites** during *spring 2026* <u>with underlined</u> ~~and struck text.~~
 
## 1.1 Key findings
 
* Rainfall rose 12% year on year
* Sensor uptime reached 99.2%
* Two stations need new batteries
* Nested item under batteries
 
## 1.2 Next steps
 
1. Order batteries
2. Recalibrate sensors
3. Publish dataset
 
# 2. Measurements
 
|  |  |  |  |
| --- | --- | --- | --- |
| Station | Rainfall (mm) | Uptime | Notes |
| Alpha | 412.5 | 99.2% | Battery low |
| Bravo | 388.0 | 97.8% | OK | stable |
| Charlie | 451.3 | 99.9% | New sensor |
 
## 2.1 Chart
 
![](data:image/png;base64...)
 
Figure 1: Quarterly revenue chart.
 
### 3. Deep heading level three
 
Contact: hello@example.org — see https://example.org/data for the dataset. Unicode check: café, naïve, 東京, Ω, emoji 🙂.
  1. changed heading becomes plain text: Pilot Report: Field Station Alpha
  2. kept heading: 1. Summary
  3. kept paragraph: This report covers three sites during sp
  4. kept heading: 1.1 Key findings
  5. kept list: Rainfall rose 12% year on year
  6. kept heading: 1.2 Next steps
  7. kept list: Order batteries
  8. kept heading: 2. Measurements
  9. kept table: Station
markitdown 0.1.9 · Linux (lab container) · 2026-11-15 · proof data

On our 15-file Word corpus (real files from other tools plus synthetic ones) the grades were 4 A, 7 B, 2 C and 2 X, the two X being a corrupt file and a zero-byte file (grading method).

How MarkItDown reads a Word file

The document is turned into HTML by the Mammoth library using Word styles, and the HTML is turned into Markdown. So what matters is the style applied in Word, not how the text looks: a line made big and bold by hand is a paragraph; a line in the Heading 2 style is a ##.

The document title is not a heading

Paragraphs in the Title and Subtitle styles come out as plain paragraphs:

Title and Subtitle styles, default
The Document Title

A subtitle line

# First section

Body text.
docx-W01.md · 64 bytes output (.md)

Mapping the styles fixes it (the full mechanism is below):

Title => h1, Subtitle => h2
# The Document Title

## A subtitle line

# First section

Body text.
docx-W01c.md · 69 bytes output (.md)

Tables: the empty header row and the pipe problem

The header row is empty

A table whose first row is not flagged as a header row in Word gets an empty header line, with the real header as the first data row:

Table without the header flag
|  |  |  |
| --- | --- | --- |
| Station | Rainfall | Notes |
| Alpha | 412.5 | ok |
| Bravo | 388.0 | low |
docx-W07b.md · 108 bytes output (.md)

The same table with the flag set (Table Design, Header Row, then Repeat as header row) comes out right:

Table with the header flag
| Station | Rainfall | Notes |
| --- | --- | --- |
| Alpha | 412.5 | ok |
| Bravo | 388.0 | low |
docx-W07.md · 97 bytes output (.md)

Merged cells, multi-paragraph cells, nested tables and a 12-column table all produced a table with the empty header row; the merged title appeared once in its first cell and the other cells were empty (sample files: no header flag, header flag).

A | inside a cell breaks the row

Unlike the CSV converter, Word cell text is not escaped, so OK | stable adds a column:

A cell containing a pipe
|  |  |
| --- | --- |
| Key | Value |
| state | OK | stable |
docx-W09.md · 61 bytes output (.md)

The workaround we tested is to escape the pipe in the file before converting; it produced OK \| stable:

After escaping the pipe in the DOCX XML
|  |  |
| --- | --- |
| Key | Value |
| state | OK \| stable |
docx-W09b.md · 62 bytes output (.md)

The recipe is in lab/scripts/t07_docx.py (escape_pipes).

Lists: when nesting survives

It depends on how the list was made. Real multi-level lists (what Word produces) keep their nesting, with the bullet character alternating *, +, -:

Nested bullets with list levels
* Top one
  + Second level
    - Third level
* Top two
docx-W05b.md · 54 bytes output (.md)

Lists built by applying a different paragraph style to each line (List Bullet 2, List Bullet 3) are flattened to one level:

Nested bullets by paragraph style
* Top one
* Second level
* Third level
* Top two
docx-W05.md · 48 bytes output (.md)

Numbered lists with real levels come out as 1. 2. 3. with the nested item indented; the style-based version numbers the nested item as a fourth top-level item. Sample with list levels, sample with styles.

Images inside Word files

Each embedded picture becomes ![](data:image/png;base64...): the data is cut off, and the alt text, when the picture has one, is kept:

A picture with alt text
![A bar chart of quarterly revenue](data:image/png;base64...)
docx-W14.md · 61 bytes output (.md)

With keep_data_uris=True the full base64 stays (our file's output grew from 44 to 11,246 characters). Extracting pictures to files and descriptions: image page.

Customising with style_map

style_map is a Mammoth style-mapping rule list passed to the constructor, so it is Python only: there is no command-line option for it (CLI reference). Three tested mappings, applied together:

Pythonapi-style-map-custom.py
from markitdown import MarkItDown

# Title and Subtitle paragraph styles, a custom paragraph style and a custom character style
rules = "\n".join([
    "p[style-name='Title'] => h1:fresh",
    "p[style-name='Subtitle'] => h2:fresh",
    "p[style-name='CodeBlock'] => pre:fresh",
    "r[style-name='Highlight Phrase'] => em",
])
md = MarkItDown(style_map=rules)
print(md.convert("samples/docx-title-subtitle.docx").markdown.split("\n\n")[0:2])
print(md.convert("samples/docx-custom-styles.docx").markdown)
Output · markitdown 0.1.9 · Python 3.13.18 · 2026-11-15
['# The Document Title', '## A subtitle line']
```
print('hello')
```

A *key phrase* inside text.

captured result

Without a mapping, custom styles come out as ordinary text:

Custom styles, no mapping
print('hello')

A key phrase inside text.
docx-W28.md · 41 bytes output (.md)

A mapping cannot infer headings from appearance and does not affect tables. We did not test how rules embedded in the document interact with yours. Sample with the custom styles.

Footnotes, comments, tracked changes, headers and footers

  • Footnotes survive as text, but the reference becomes a link to #footnote-N and the note is a numbered list at the end.
  • Comments are lost: the comment text is not in the output.
  • Tracked changes: inserted text is kept and deleted text does not appear, which silently changes the meaning if you needed to see the deletions.
  • Headers and footers are lost.
A footnote
A sentence with a note.[[1]](#footnote-20)

1. The footnote text itself. [↑](#footnote-ref-20)
docx-W20.md · 96 bytes output (.md)

Equations

Word equations come out as LaTeX between $ for inline and $$ for display:

Inline and display equation
Inline $x^{2}+y^{2}=z^{2}$ and display:

$$\frac{a}{b}=c$$
docx-W22.md · 58 bytes output (.md)

Legacy .doc files

A .doc file raises UnsupportedFormatException. The route we tested: convert it to .docx with LibreOffice in headless mode, then MarkItDown. The result was identical to converting the original DOCX:

Command
soffice --headless --convert-to docx report.doc

Several files: batch conversion. .rtf and .odt: the formats page.

Errors specific to Word files

Reproduced by us · fixed in 0.1.9

DocxConverter threw IndexError with message: pop from empty list

A field-end mark with no matching field-begin mark in the document made the DOCX reader (mammoth before 1.12.2) pop from an empty list.

Affected: 0.1.6 and 0.1.8 (tested; mammoth 1.11) · last reproduced 2026-11-15 · Upstream report

Reported, not reproduced by us

DocxConverter threw KeyError with message: 'w:ilvl'

Reported for DOCX files written by tools other than Word; the underlying DOCX reader (mammoth) fails on a numbering definition it does not expect.

Affected: reported on 0.1.x · Upstream report

A file written by LibreOffice, with nested lists and a table, converted without an error in our test (row W25); we could not produce the w:ilvl error ourselves.

Files from Google Docs, LibreOffice and Pages

LibreOffice files convert, with nested lists intact and the same empty table header row. We did not have Google Docs or Pages exports to test, so we make no claim about them.

Version notes for Word

  • since 0.1.2 Equations in DOCX.
  • since 0.1.3 Fixes for alt text with line breaks and for linked images.
  • since 0.1.4 Newer Mammoth (1.11).
  • since 0.1.9 Mammoth 1.12.2 or newer is required.

Mammoth or Pandoc?

We built the test files for this page with Pandoc but did not compare its conversion with MarkItDown's. MarkItDown is one tool for many formats and returns text meant for language models: the comparison.