用Python中的prettyprint类包装标记代码块
在python中,有一个标记扩展,它突出显示了codehilite代码。此扩展将代码段封装在codehilite类中。我怎样才能得到这样一个函数,而不使用codehilite处理,只在每个代码片段上加class='prettyprint'用Python中的prettyprint类包装标记代码块,python,css,django,prettify,Python,Css,Django,Prettify,在python中,有一个标记扩展,它突出显示了codehilite代码。此扩展将代码段封装在codehilite类中。我怎样才能得到这样一个函数,而不使用codehilite处理,只在每个代码片段上加class='prettyprint' 基本上,将markdown生成的每个标记转换为为什么不使用str.replace()或're.subn()'?例如: replaced = markup.replace('<pre>', '<pre class="prettyprint"&g
基本上,将markdown生成的每个
标记转换为
为什么不使用str.replace()
或're.subn()'?例如:
replaced = markup.replace('<pre>', '<pre class="prettyprint">')
replaced=markup.replace(“”,“”)
或
replaced=re.subn(“(]*)”,“\\1 class=“prettyprint”,标记)
如果您遇到Django模板,那么这不是问题所在。只需使用render\u to\u string()
replaced = re.subn('(<pre[^>]*)', '\\1 class="prettyprint"', markup)