Applying formatting inside a pandoc code block

Viewed 884

Is there any way to apply formatting inside a code block in pandoc markdown? As an example, consider the following:

```cpp
void foo() noexcept(*see below*);
```

I'd like the "see below" part to be italicized inside the code block - however the * characters appear verbatim in the result. I've also tried using <i> HTML tags, with the same result.

Is there any solution to this problem that does not require postprocessing of the generated document?

1 Answers

You cannot control formatting inside code blocks at this arbitrary level where you decide yourself which parts to italize and which not. Code block is code block which means that the content is rendered verbatim.

However, you can apply a syntax highlighter to code blocks. A syntax highlighter has some knowledge about programming languages and can identify keywords and idiomatic parts to apply its own rules to these inside code blocks.

To see which syntax highlight styles are available for your version of Pandoc, run:

pandoc --list-highlight-styles

On this system the highlighters are: espresso, haddock, kate, monochrome, pygments, tango, zenburn. To see which languages the highlighters can handle, run:

pandoc --list-highlight-languages

My Pandoc spits out a list of 141 languages. cpp is amongst them.

I created sample results from your code snippet (without the **) for all styles and put them into a JPEG below. From top to bottom: espresso, haddock, kate, monochrome, pygments, tango, zenburn. As you can see, the two words you wanted are not highlighted, but some hey words and key syntax elements of CPP are: Pandoc highlighting styles from top to bottom: espresso, haddock, kate, monochrome, pygments, tango, zenburn

Related