<s> r"""<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> from django import template <EOL> from django . template . defaultfilters import stringfilter <EOL> from django . utils . safestring import mark_safe <EOL> try : <EOL> from pygments import highlight <EOL> from pygments . formatters import HtmlFormatter <EOL> from pygments . lexers import get_lexer_by_name , guess_lexer , ClassNotFound <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> register = template . Library ( ) <EOL> @ register . simple_tag <EOL> def pygments_css ( ) : <EOL> return HtmlFormatter ( ) . get_style_defs ( '<STR_LIT>' ) <EOL> def generate_pygments_css ( path = None ) : <EOL> if path is None : <EOL> import os <EOL> path = os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) <EOL> f = open ( path , '<STR_LIT:w>' ) <EOL> f . write ( pygments_css ( ) ) <EOL> f . close ( ) <EOL> def get_lexer ( value , arg ) : <EOL> if arg is None : <EOL> return guess_lexer ( value ) <EOL> return get_lexer_by_name ( arg ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> @ stringfilter <EOL> def colorize ( value , arg = None ) : <EOL> try : <EOL> return mark_safe ( highlight ( value , get_lexer ( value , arg ) , HtmlFormatter ( ) ) ) <EOL> except ClassNotFound : <EOL> return value <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> @ stringfilter <EOL> def colorize_table ( value , arg = None ) : <EOL> try : <EOL> return mark_safe ( highlight ( value , get_lexer ( value , arg ) , HtmlFormatter ( linenos = '<STR_LIT>' ) ) ) <EOL> except ClassNotFound : <EOL> return value <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> @ stringfilter <EOL> def colorize_noclasses ( value , arg = None ) : <EOL> try : <EOL> return mark_safe ( highlight ( value , get_lexer ( value , arg ) , HtmlFormatter ( noclasses = True ) ) ) <EOL> except ClassNotFound : <EOL> return value </s>
