[英]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.我需要使用 Pandoc 将一些 HTML 转换为 Markdown。 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.
我需要它们作为带有语法定义的反引号代码块出现在生成的 Markdown 文档中。
For example, if I have such source HTML:例如,如果我有这样的源 HTML:
<pre class="python"><code>
def myfunc(param):
'''Description of myfunc'''
return do_something(param)
</code></pre>
I want Pandoc to convert it into:我希望 Pandoc 将其转换为:
```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.它几乎就在那里,但语法定义在花括号和一个点中,我的 Markdown 解析器无法识别。 How can I get
```python
instead of ``` {.python}
when converting HTML to Markdown?将 HTML 转换为 Markdown 时,如何获得
```python
而不是``` {.python}
?
I have control over the source HTML, so I can change it the way needed.我可以控制源 HTML,因此我可以根据需要更改它。 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.
如果有一个选项可以将“原始降价”插入到 HTML 中,这将被 Pandoc 忽略,这对我也有用,我可以按照我需要的方式将这些块嵌入到源 HTML 中,但我需要告诉 Pandoc 不要触摸他们。 But I can't find such option in the docs.
但是我在文档中找不到这样的选项。
This behavior is governed by thefenced_code_attributes
extension.此行为由
fenced_code_attributes
扩展控制。 It is enabled by default;默认开启; disabling it will give your desired output:
禁用它会给出你想要的输出:
pandoc --to=markdown-fenced_code_attributes ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.