Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Python中的prettyprint类包装标记代码块_Python_Css_Django_Prettify - Fatal编程技术网

用Python中的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

在python中,有一个标记扩展,它突出显示了codehilite代码。此扩展将代码段封装在codehilite类中。我怎样才能得到这样一个函数,而不使用codehilite处理,只在每个代码片段上加class='prettyprint'


基本上,将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)