Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Pandoc mark text inside a code block?

I use <mark>...</mark> to highlight text in a Markdown document, such as the Google Python Style Guide. I am having difficulty higlighting code. For example, I want to highlight how to annotate with types:

```python
<mark>def func(a: int) -> List[int]:</mark>
```

but this pandoc command:

pandoc -s -t html5 -o "Google Python style guide.html" "Google Python style guide.md"

shows <mark> and </mark> as code and does not render an HTML highlight.

One solution is to use a pre tag, such as:

<pre><mark>def func(a: int) -> List[int]:</mark></pre>

which does render an HTML highlight.

Can Pandoc render the HTML higlights without having to convert all ```python blocks to pre tags?

like image 330
miguelmorin Avatar asked Oct 15 '25 02:10

miguelmorin


1 Answers

No, not by default. How is pandoc supposed to know the <mark> is not part of your code?

However, you can write a pandoc filter that matches on each code block and converts it to a raw html block. Something like (untested):

function CodeBlock(elem)
  html = "<pre>" .. elem.text .. "</pre>"
  return pandoc.RawBlock("html", html)
end

Note that you'll have to make sure you don't have other unescaped HTML in your code blocks.

Update

If you also want syntax highlighting, probably you want to try the pandoc-emphasize-code filter.

like image 98
mb21 Avatar answered Oct 18 '25 01:10

mb21



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!