Enhance highlight.py PEP8
This commit is contained in:
+13
-13
@@ -182,8 +182,8 @@ class Highlighter(object):
|
|||||||
)),
|
)),
|
||||||
'PYTHONMultilineString': (python_tokenizer,
|
'PYTHONMultilineString': (python_tokenizer,
|
||||||
(('ENDMULTILINESTRING',
|
(('ENDMULTILINESTRING',
|
||||||
re.compile(r'.*?("""|\'\'\')',
|
re.compile(r'.*?("""|\'\'\')',
|
||||||
re.DOTALL), 'color: darkred'), )),
|
re.DOTALL), 'color: darkred'), )),
|
||||||
'HTML': (html_tokenizer, (
|
'HTML': (html_tokenizer, (
|
||||||
('GOTOPYTHON', re.compile(r'\{\{'), 'color: red'),
|
('GOTOPYTHON', re.compile(r'\{\{'), 'color: red'),
|
||||||
('COMMENT', re.compile(r'<!--[^>]*-->|<!>'),
|
('COMMENT', re.compile(r'<!--[^>]*-->|<!>'),
|
||||||
@@ -209,7 +209,7 @@ class Highlighter(object):
|
|||||||
mode = self.mode
|
mode = self.mode
|
||||||
while i < len(data):
|
while i < len(data):
|
||||||
for (token, o_re, style) in Highlighter.all_styles[mode][1]:
|
for (token, o_re, style) in Highlighter.all_styles[mode][1]:
|
||||||
if not token in self.suppress_tokens:
|
if token not in self.suppress_tokens:
|
||||||
match = o_re.match(data, i)
|
match = o_re.match(data, i)
|
||||||
if match:
|
if match:
|
||||||
if style:
|
if style:
|
||||||
@@ -221,7 +221,7 @@ class Highlighter(object):
|
|||||||
new_mode = \
|
new_mode = \
|
||||||
Highlighter.all_styles[mode][0](self,
|
Highlighter.all_styles[mode][0](self,
|
||||||
token, match, style)
|
token, match, style)
|
||||||
if not new_mode is None:
|
if new_mode is not None:
|
||||||
mode = new_mode
|
mode = new_mode
|
||||||
i += max(1, len(match.group()))
|
i += max(1, len(match.group()))
|
||||||
break
|
break
|
||||||
@@ -241,9 +241,9 @@ class Highlighter(object):
|
|||||||
style = self.styles[token]
|
style = self.styles[token]
|
||||||
if self.span_style != style:
|
if self.span_style != style:
|
||||||
if style != 'Keep':
|
if style != 'Keep':
|
||||||
if not self.span_style is None:
|
if self.span_style is not None:
|
||||||
self.output.append('</span>')
|
self.output.append('</span>')
|
||||||
if not style is None:
|
if style is not None:
|
||||||
self.output.append('<span style="%s">' % style)
|
self.output.append('<span style="%s">' % style)
|
||||||
self.span_style = style
|
self.span_style = style
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ def highlight(
|
|||||||
):
|
):
|
||||||
styles = styles or {}
|
styles = styles or {}
|
||||||
attributes = attributes or {}
|
attributes = attributes or {}
|
||||||
if not 'CODE' in styles:
|
if 'CODE' not in styles:
|
||||||
code_style = """
|
code_style = """
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
font-family: Bitstream Vera Sans Mono,monospace;
|
font-family: Bitstream Vera Sans Mono,monospace;
|
||||||
@@ -272,7 +272,7 @@ def highlight(
|
|||||||
white-space: pre !important;\n"""
|
white-space: pre !important;\n"""
|
||||||
else:
|
else:
|
||||||
code_style = styles['CODE']
|
code_style = styles['CODE']
|
||||||
if not 'LINENUMBERS' in styles:
|
if 'LINENUMBERS' not in styles:
|
||||||
linenumbers_style = """
|
linenumbers_style = """
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
font-family: Bitstream Vera Sans Mono,monospace;
|
font-family: Bitstream Vera Sans Mono,monospace;
|
||||||
@@ -283,7 +283,7 @@ def highlight(
|
|||||||
color: #A0A0A0;\n"""
|
color: #A0A0A0;\n"""
|
||||||
else:
|
else:
|
||||||
linenumbers_style = styles['LINENUMBERS']
|
linenumbers_style = styles['LINENUMBERS']
|
||||||
if not 'LINEHIGHLIGHT' in styles:
|
if 'LINEHIGHLIGHT' not in styles:
|
||||||
linehighlight_style = "background-color: #EBDDE2;"
|
linehighlight_style = "background-color: #EBDDE2;"
|
||||||
else:
|
else:
|
||||||
linehighlight_style = styles['LINEHIGHLIGHT']
|
linehighlight_style = styles['LINEHIGHLIGHT']
|
||||||
@@ -333,8 +333,9 @@ def highlight(
|
|||||||
== '_' and value])
|
== '_' and value])
|
||||||
if fa:
|
if fa:
|
||||||
fa = ' ' + fa
|
fa = ' ' + fa
|
||||||
return '<table%s><tr style="vertical-align:top;"><td style="min-width:40px; text-align: right;"><pre style="%s">%s</pre></td><td><pre style="%s">%s</pre></td></tr></table>'\
|
return '<table%s><tr style="vertical-align:top;">' \
|
||||||
% (fa, linenumbers_style, numbers, code_style, code)
|
'<td style="min-width:40px; text-align: right;"><pre style="%s">%s</pre></td>' \
|
||||||
|
'<td><pre style="%s">%s</pre></td></tr></table>' % (fa, linenumbers_style, numbers, code_style, code)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -342,5 +343,4 @@ if __name__ == '__main__':
|
|||||||
argfp = open(sys.argv[1])
|
argfp = open(sys.argv[1])
|
||||||
data = argfp.read()
|
data = argfp.read()
|
||||||
argfp.close()
|
argfp.close()
|
||||||
print('<html><body>' + highlight(data, sys.argv[2])\
|
print('<html><body>' + highlight(data, sys.argv[2]) + '</body></html>')
|
||||||
+ '</body></html>')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user