#NEWLINE# def highlight_syntax( src , lang , linenums = False ) : #NEWLINE# #INDENT# 'Pass code to the [Pygments](http://pygments.pocoo.org/) highliter\n    with optional line numbers. The output should then be styled with CSS\n    to  your liking. No styles are applied by default - only styling hooks\n    (i.e.: <span class="k">).\n    ' #NEWLINE# src = src . strip ( '\n' ) #NEWLINE# if ( not lang ) : #NEWLINE# #INDENT# lexer = TextLexer ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# lexer = get_lexer_by_name ( lang , stripall = True ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# lexer = TextLexer ( ) #NEWLINE# #UNINDENT# #UNINDENT# formatter = HtmlFormatter ( linenos = linenums , tab_length = TAB_LENGTH ) #NEWLINE# html = highlight ( src , lexer , formatter ) #NEWLINE# if lang : #NEWLINE# #INDENT# open_code = ( OPEN_CODE % ( ( LANG_TAG % ( lang , ) ) , ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# open_code = ( OPEN_CODE % '' ) #NEWLINE# #UNINDENT# html = html . replace ( '<div class="highlight"><pre>' , open_code , 1 ) #NEWLINE# html = html . replace ( '</pre></div>' , CLOSE_CODE ) #NEWLINE# return html