def render lexer_name code numbers True inline_styles False format htm

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def render(lexer_name, code, numbers=True, inline_styles=False, format='html'):
try:
lexer = lexers.get_lexer_by_name(lexer_name)
except lexers.ClassNotFound:
lexer_name = 'text'
lexer = lexers.get_lexer_by_name(lexer_name)
if 'php' == lexer_name:
lexer.startinline = True
linenos = numbers and 'table' or False
if format == 'html':
formatter = HtmlFormatter(linenos=linenos, noclasses=inline_styles)
else:
formatter = BBCodeFormatter()
output = highlight(code, lexer, formatter)
return output