# # # patch "config.py.example" # from [8c311335fc01aebe2a40524a71914fd828471873] # to [72e1751fec732e26d074c3e5a980a0f71c3d3ed3] # # patch "syntax.py" # from [510d8085a40d9e86afbb71cafcbc6cf6a1205566] # to [cf93e6e6a6166204daaae6ec50819ba175fa3ed1] # ============================================================ --- config.py.example 8c311335fc01aebe2a40524a71914fd828471873 +++ config.py.example 72e1751fec732e26d074c3e5a980a0f71c3d3ed3 @@ -31,7 +31,9 @@ gnome_mimetype_uri = 'mimetypes/' # and where they are on the web gnome_mimetype_uri = 'mimetypes/' -# highlight +# highlight from http://andre-simon.de/ +# if you don't have this available, just comment +# the "highlight_command" line out highlight_command = '/opt/local/bin/highlight' graphopts = { ============================================================ --- syntax.py 510d8085a40d9e86afbb71cafcbc6cf6a1205566 +++ syntax.py cf93e6e6a6166204daaae6ec50819ba175fa3ed1 @@ -5,19 +5,32 @@ import select import config import popen2 import select +import cgi mime_to_lang = { } -def highlight(lines, language='py'): +def highlight(*args, **kwargs): + # if we don't have a highlighter, let's just return the original + # iterator + if not hasattr(config, "highlight_command"): + return __basic_highlight(*args, **kwargs) + else: + return __highlight(*args, **kwargs) + +def __basic_highlight(lines, language='py'): + for line in lines: + yield cgi.escape(line.rstrip('\n')) + +def __highlight(lines, language='py'): """A generator which will read lines from the given input stream, and yield them back in syntax highlighted, HTML format. """ # trickier than this initially looks; the syntax highlighter might not necessarily # have any more data for us, so it's necessary to use select() and write new data # as it wants it, and read it back (buffer and yield lines) as possible. - + # # this assumes the 'highlight' command, although shouldn't take much work to have this # happy with other highlighters.