【问题标题】:Wrap markdown code blocks with prettyprint classes in Python在 Python 中用漂亮的打印类包装 markdown 代码块
【发布时间】:2013-07-17 19:00:18
【问题描述】:

在 python 中有一个 markdown 扩展,可以突出显示 codehilite 的代码。此扩展将 sn-ps 包装在 codehilite 类中。我怎样才能获得这样的功能,但只在每个 sn-p 上放置 class='prettyprint' 而不使用 codehilite 处理。

基本上将markdown制作的每个<pre></pre>标签转换为<pre class='prettyprint'></pre>

【问题讨论】:

    标签: python css django prettify


    【解决方案1】:

    为什么不使用str.replace() 或're.subn()'?例如:

    replaced = markup.replace('<pre>', '<pre class="prettyprint">')
    

    replaced = re.subn('(<pre[^>]*)', '\\1 class="prettyprint"', markup)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2014-05-12
    相关资源
    最近更新 更多