Skip to content
FileMyLove

Markdown to Word: preserve literal symbols in examples

Use code blocks when Markdown symbols are content, then check characters, spaces and block boundaries in the converted Word document.

By FileMyLove Team1 min read

A Markdown guide contains # or *, but the Word copy shows a heading or list instead. Decide whether each symbol is intended as formatting syntax or literal content before correcting the source.

Put literal examples in code blocks

Pandoc documents that verbatim code blocks preserve spaces and line breaks without interpreting special characters as Markdown formatting. They suit command examples, settings and text that must be checked character by character.

This source example uses three tildes to open and close a block, with blank lines around it:

~~~
# sample heading text
* sample marker
~~~

The intended output displays the two inner lines with their symbols. The opening and closing fences are syntax, not part of the DOCX example text.

Apply it selectively

Content Our suggested treatment
A real document heading Normal Markdown heading syntax
An example needing literal # and * Code block
Explanatory paragraphs Outside the block
Example containing a fence already Use a longer outer fence

Do not wrap an entire guide in a code block merely to preserve a few symbols: real headings and lists would also become example text.

Inspect the converted file

  1. Retain the source and open Markdown to Word.
  2. Convert the file to DOCX.
  3. Compare symbols, spaces and example lines in Word.
  4. Check the paragraph after each block for a missing closing fence.
  5. If you will reuse a command, compare the copied text against the original again.

FileMyLove uses Pandoc's Markdown reader and DOCX writer. Conversion does not execute the example commands, and fonts or highlighting need not match every Markdown editor.

Keep an executable source separately

Word is useful for a readable guide, but we recommend retaining the actual code or plain-text source separately when it must be used later. See headings and lists in Word, and table column checks for other document structures.