better highlight.py, thanks Paolo
This commit is contained in:
+30
-34
@@ -27,7 +27,7 @@ class Highlighter(object):
|
|||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Initialize highlighter:
|
Initialize highlighter:
|
||||||
mode = language (PYTHON, WEB2PY,C, CPP, HTML, HTML_PLAIN)
|
mode = language (PYTHON, WEB2PY, C, CPP, HTML, HTML_PLAIN)
|
||||||
"""
|
"""
|
||||||
styles = styles or {}
|
styles = styles or {}
|
||||||
mode = mode.upper()
|
mode = mode.upper()
|
||||||
@@ -260,33 +260,27 @@ def highlight(
|
|||||||
):
|
):
|
||||||
styles = styles or {}
|
styles = styles or {}
|
||||||
attributes = attributes or {}
|
attributes = attributes or {}
|
||||||
if 'CODE' not in styles:
|
code_style = styles.get('CODE', None) or '''
|
||||||
code_style = """
|
font-size: 11px;
|
||||||
font-size: 11px;
|
font-family: Bitstream Vera Sans Mono,monospace;
|
||||||
font-family: Bitstream Vera Sans Mono,monospace;
|
background-color: transparent;
|
||||||
background-color: transparent;
|
margin: 0;
|
||||||
margin: 0;
|
padding: 5px;
|
||||||
padding: 5px;
|
border: none;
|
||||||
border: none;
|
overflow: auto;
|
||||||
overflow: auto;
|
white-space: pre !important;
|
||||||
white-space: pre !important;\n"""
|
'''
|
||||||
else:
|
linenumbers_style = styles.get('LINENUMBERS', None) or '''
|
||||||
code_style = styles['CODE']
|
font-size: 11px;
|
||||||
if 'LINENUMBERS' not in styles:
|
font-family: Bitstream Vera Sans Mono,monospace;
|
||||||
linenumbers_style = """
|
background-color: transparent;
|
||||||
font-size: 11px;
|
margin: 0;
|
||||||
font-family: Bitstream Vera Sans Mono,monospace;
|
padding: 5px;
|
||||||
background-color: transparent;
|
border: none;
|
||||||
margin: 0;
|
color: #A0A0A0;
|
||||||
padding: 5px;
|
'''
|
||||||
border: none;
|
linehighlight_style = styles.get('LINEHIGHLIGHT', None) or \
|
||||||
color: #A0A0A0;\n"""
|
'background-color: #EBDDE2;'
|
||||||
else:
|
|
||||||
linenumbers_style = styles['LINENUMBERS']
|
|
||||||
if 'LINEHIGHLIGHT' not in styles:
|
|
||||||
linehighlight_style = "background-color: #EBDDE2;"
|
|
||||||
else:
|
|
||||||
linehighlight_style = styles['LINEHIGHLIGHT']
|
|
||||||
|
|
||||||
if language and language.upper() in ['PYTHON', 'C', 'CPP', 'HTML',
|
if language and language.upper() in ['PYTHON', 'C', 'CPP', 'HTML',
|
||||||
'WEB2PY']:
|
'WEB2PY']:
|
||||||
@@ -309,18 +303,20 @@ def highlight(
|
|||||||
else:
|
else:
|
||||||
lineno = highlight_line
|
lineno = highlight_line
|
||||||
if lineno < len(lines):
|
if lineno < len(lines):
|
||||||
lines[lineno] = '<div style="%s">%s</div>' % (
|
lines[lineno] = '<span style="%s">%s</span>' % (
|
||||||
linehighlight_style, lines[lineno])
|
linehighlight_style, lines[lineno])
|
||||||
linenumbers[lineno] = '<div style="%s">%s</div>' % (
|
linenumbers[lineno] = '<span style="%s">%s</span>' % (
|
||||||
linehighlight_style, linenumbers[lineno])
|
linehighlight_style, linenumbers[lineno])
|
||||||
|
|
||||||
if context_lines:
|
if context_lines:
|
||||||
if lineno + context_lines < len(lines):
|
if lineno + context_lines < len(lines):
|
||||||
del lines[lineno + context_lines:]
|
delslice = slice(lineno + context_lines + 1, len(lines))
|
||||||
del linenumbers[lineno + context_lines:]
|
del lines[delslice]
|
||||||
|
del linenumbers[delslice]
|
||||||
if lineno - context_lines > 0:
|
if lineno - context_lines > 0:
|
||||||
del lines[0:lineno - context_lines]
|
delslice = slice(0, lineno - context_lines)
|
||||||
del linenumbers[0:lineno - context_lines]
|
del lines[delslice]
|
||||||
|
del linenumbers[delslice]
|
||||||
|
|
||||||
code = '<br/>'.join(lines)
|
code = '<br/>'.join(lines)
|
||||||
numbers = '<br/>'.join(linenumbers)
|
numbers = '<br/>'.join(linenumbers)
|
||||||
|
|||||||
Reference in New Issue
Block a user