1
votes

I need to convert some HTML to Markdown with Pandoc. All is fine except the code blocks in my document are not converted properly. I need them to appear in the resulting Markdown document as backtick-code blocks with syntax definition.

For example, if I have such source HTML:

<pre class="python"><code>
    def myfunc(param):
        '''Description of myfunc'''
        return do_something(param)
</code></pre>

I want Pandoc to convert it into:

```python
    def myfunc(param):
        '''Description of myfunc'''
        return do_something(param)
```

But what I am getting is:

``` {.python}
    def myfunc(param):
        '''Description of myfunc'''
        return do_something(param)
```

It's almost there, but the syntax definition is in curly braces and with a dot, which is not recognised by my Markdown parser. How can I get ```python instead of ``` {.python} when converting HTML to Markdown?

I have control over the source HTML, so I can change it the way needed. If there's an option to insert "raw markdown" into the HTML which will be ignored by Pandoc, that would work for me too, I can embed those blocks into the source HTML the way I need, but I need to tell Pandoc not to touch them. But I can't find such option in the docs.

1

1 Answers

1
votes

This behavior is governed by the fenced_code_attributes extension. It is enabled by default; disabling it will give your desired output:

pandoc --to=markdown-fenced_code_attributes ...