Using Pandoc 1.17.2 and Word 2013, I finally found a solution, it seems that later versions of Pandoc use a related style that is hidden by default in Word.
Step 1. Create a custom template file using
pandoc -o template_1.17.2.docx test.md
Where test.md contains the source code and all other styles that you can change. For example:
~~~~ this is preformatted source using style "Source Code" ~~~~ ~~~ xml <this> is preformatted source using "KeyworkTok" and "NormalTok"</this> ~~~
Open the Word_1.17.2.docx template in Word. Source code is now formatted using the hidden linked style "Source Code". This style is NOT displayed in the default style preview area, you can add it by customizing the style preview panel by clicking the small square arrow in the lower right corner of the style preview panel.
Change this style as you like and save the template. Then generate a document based on this template:
pandoc --reference-docx=template_1.17.2.docx -o mydoc.docx mydoc.md
You should now see the source correctly formatted in mydoc.
@LinusR suggests that different source styles use different Layout styles. I added XML as an example. Formatted XML will use KeywordTok and NormalTok.
Karl Ivar Dahl
source share