1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | from BeautifulSoup import BeautifulSoup
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import guess_lexer, get_lexer_by_name
import re
def Parse ( content ):
tree = BeautifulSoup ( content )
for code in tree.findAll ( 'code' ):
if not code['class']: code['class'] = 'text'
lexer = get_lexer_by_name(code['class'])
new_content = highlight ( code.contents[0], lexer, HtmlFormatter() )
code.replaceWith ( "%s\n%s" % (info,new_content) )
content = str(tree)
return content
|
Comments
What is "info"?
#
Might be a good idea to mention that it requires two libraries, BeautifulSoup and pygments. Also on line 20, you pass the format string an info variable which, from what I can see, isn't set.
Both content and new_content are excessive variables, especially content.
#
This is a good idea. But how am I supposed to use this feature? ie where does the
contentcome from?#