Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying formatting inside a pandoc code block

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?

like image 643
Vittorio Romeo Avatar asked Nov 26 '17 23:11

Vittorio Romeo


People also ask

What is code block formatting?

Codes Blocks uses Google's Apps Script, a server-side JavaScript platform, to interact with Docs and format code. Each time the add-on formats a snippet of code, a request is made to the Apps Script backend to modify the current Doc.

What font does pandoc use?

Pandoc uses LaTeX per default for PDF generation, so it depends on your TeX installation. If you're on TeX Live you can use all in this font catalogue.

How do you use extensions in pandoc?

Background. Pandoc's markdown lets you specify extensions for how you would like your markdown to be handled: Markdown syntax extensions can be individually enabled or disabled by appending +EXTENSION or -EXTENSION to the format name.

How do you mark a code block in Markdown?

The basic Markdown syntax allows you to create code blocks by indenting lines by four spaces or one tab. If you find that inconvenient, try using fenced code blocks. Depending on your Markdown processor or editor, you'll use three backticks ( ``` ) or three tildes ( ~~~ ) on the lines before and after the code block.


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

like image 59
Kurt Pfeifle Avatar answered Oct 07 '22 08:10

Kurt Pfeifle