0

How can I convert a Markdown file to PDF and preserve the code block formatting?

The Markdown code

JSON
{
  "client_id": "string",
  "api_key": "string",
  "data": {

as served up via Mkdocs looks like:

EX_1

enter image description here

After converting the Markdown file to PDF (or docx, etc.), the formatting looks like this:

EX_2

enter image description here

I need to preserve the background color and the line numbering illustrated in EX_1.

Jongware
  • 22,200
  • 8
  • 54
  • 100
FunnyChef
  • 1,880
  • 3
  • 18
  • 30
  • No, the images were added here to illustrate the difference in output. I'll update the issue with the code snippet. – FunnyChef Jan 18 '18 at 22:41
  • Ah I get it. I edited your input to the top, and only then what it looks like in your editor. That makes things clearer. – Jongware Jan 19 '18 at 00:01

1 Answers1

0

For those who may run into a similar issue the following fixed the issue for me;

  1. Create a file named preamble.tex
  2. Add the following to the file and save: \usepackage{longtable}\setlength{\LTleft}{0em}
  3. Run your pan doc command; pandoc test.md -o test.pdf -H preamble.tex
FunnyChef
  • 1,880
  • 3
  • 18
  • 30