简体   繁体   中英

Add proper syntax name to code blocks when converting from HTML to Markdown with Pandoc

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.

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

pandoc --to=markdown-fenced_code_attributes ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM