2013-07-17 98 views
0

在python中有一个markdown扩展,它突出显示codehilite的代码。该扩展将代码片段包装在codehilite类中。我怎样才能得到这样的功能,但只在每个片段上放置class ='prettyprint'而不用codehilite处理。在Python中使用prettyprint类包装markdown代码块

基本上为什么不使用str.replace()或 're.subn()' 每<pre></pre>标记,降价使得进入<pre class='prettyprint'></pre>

回答

1

转换?例如: -

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

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

因为我使用的模板 – Supremekhaoz

+0

如果meen Django的模板,那就没办法那么这是没有问题的。只需使用'render_to_string()'https://docs.djangoproject.com/en/1.5/ref/templates/api/#the-render-to-string-shortcut – twil

相关问题