How to enable syntax highlighting for Markdown inline code with Pandoc?

Okay, should have read a little bit further... found the solution. It's called Extension: inline_code_attributes:

Attributes can be attached to verbatim text, just as with fenced code blocks:

`<$>`{.haskell}

So the example above becomes:

This is `print("Hello world")`{.python} inline code.

Makes sense if you think about it... I'll still leave this up in case someone else has this problem.


Behind the hood, when converting Markdown to PDF, Pandoc use the \texttt command for inline code. We can hack the \texttt command to add background color for text. Add the following command to head.tex:

\definecolor{bgcolor}{HTML}{E0E0E0}
\let\oldtexttt\texttt

\renewcommand{\texttt}[1]{
  \colorbox{bgcolor}{\oldtexttt{#1}}
}

To use head.tex, use the -H option for pandoc:

pandoc --pdf-engine=xelatex -H head.tex test.md -o test.pdf