Pandoc convert docx to markdown with embedded images


Pandoc Problem Overview

When converting .docx file to markdown, the embedded image is not extracted from the docx archive, yet the output contains ![](media/image1.png){width="6.291666666666667in" height="3.1083333333333334in"}

Is there a parameter that needs to be set in order to get the embedded pictures extracted?

Pandoc Solutions

Solution 1 - Pandoc

pandoc --extract-media ./myMediaFolder input.docx -o

From the manual:

> --extract-media=DIR Extract images and other media contained in or linked from the source document to the path DIR, creating it if necessary, and adjust the images references in the document so they point to the extracted files. Media are downloaded, read from the file system, or extracted from a binary container (e.g. docx), as needed. The original file paths are used if they are relative paths not containing ... Otherwise filenames are constructed from the SHA1 hash of the contents.

Solution 2 - Pandoc

Referring to the comment by gridtrak and the problem of an unnecessarily deep directory strucutre (e.g. media/media/image2.jpeg), use the current directory as path DIR, then a folder media is created within the current directory (e.g. media/image2.jpeg):

pandoc --extract-media=. input.docx -o


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJC-View Question on Stackoverflow
Solution 1 - Pandocmb21View Answer on Stackoverflow
Solution 2 - PandocsgrubsmyonView Answer on Stackoverflow