better highlight.py, thanks Paolo
This commit is contained in:
1 parent
e8df84caa8
commit
38482d4846
1 file changed
+16
-20
+16
-20
@@ -260,8 +260,7 @@ 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;
|
||||||
@@ -269,24 +268,19 @@ def highlight(
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
border: none;
|
border: none;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
white-space: pre !important;\n"""
|
white-space: pre !important;
|
||||||
else:
|
'''
|
||||||
code_style = styles['CODE']
|
linenumbers_style = styles.get('LINENUMBERS', None) or '''
|
||||||
if 'LINENUMBERS' not in styles:
|
|
||||||
linenumbers_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;
|
||||||
color: #A0A0A0;\n"""
|
color: #A0A0A0;
|
||||||
else:
|
'''
|
||||||
linenumbers_style = styles['LINENUMBERS']
|
linehighlight_style = styles.get('LINEHIGHLIGHT', None) or \
|
||||||
if 'LINEHIGHLIGHT' not in styles:
|
'background-color: #EBDDE2;'
|
||||||
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