在 python 中有一个 markdown 扩展,它突出显示了 codehilite 的代码。此扩展将代码段包装在 codehilite 类中。我怎样才能获得这样的功能,但只在每个片段上放置 class='prettyprint' 而无需使用 codehilite 进行处理。
基本上转换每个<pre></pre>
Markdown 生成的标签 <pre class='prettyprint'></pre>
最佳答案
为什么不使用 str.replace()
或 're.subn()'?例如:
replaced = markup.replace('<pre>', '<pre class="prettyprint">')
或
replaced = re.subn('(<pre[^>]*)', '\\1 class="prettyprint"', markup)
关于python - 在 Python 中用 prettyprint 类包装 markdown 代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17708073/