Applying formatting inside a pandoc code block
Asked Answered
H

1

8

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?

Heelpiece answered 26/11, 2017 at 23:30 Comment(4)
you can always write raw HTML inside markdown... but I cannot imagine HTML being able to represent what you're suggesting here... if it's inside code and pre, then you cannot italicize some part of it...Immemorial
Try `*`see below`*` or `**`see below`**` and see if it helpsAutotoxin
Related: https://mcmap.net/q/345126/-pandoc-what-are-the-available-syntax-highlightersMonody
HTML can certainly include formatting inside preformatted blocks: <pre>cpp void foo() noexcept(<i>see below</i>);</pre>Scutage
H
3

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

Haya answered 30/4, 2021 at 14:10 Comment(1)
What is that output, is it PDF? Is it produced by Latex? I wish I had these colors in pandoc markdown -> Latex PDF output, but on my system, lstlistings barely changes color at all. What was the command line to produce this?Wristband

© 2022 - 2024 — McMap. All rights reserved.