# HG changeset patch # User Bryan O'Sullivan # Date 1194893366 28800 # Node ID 6cf7d7fe7d3d01e2bd42d253543fc3e07fd2c66f # Parent 40a06e39f010989fb6d53df6e566485d7d9bc75e highlight: clean up coding style a little diff -r 40a06e39f010 -r 6cf7d7fe7d3d hgext/highlight.py --- a/hgext/highlight.py Sat Nov 10 17:54:57 2007 -0500 +++ b/hgext/highlight.py Mon Nov 12 10:49:26 2007 -0800 @@ -44,14 +44,14 @@ from pygments.lexers import guess_lexer_for_filename, TextLexer from pygments.formatters import HtmlFormatter -SYNTAX_CSS = '\n' +SYNTAX_CSS = ('\n') class StripedHtmlFormatter(HtmlFormatter): - def __init__(self, stripecount, *args, **kwargs): super(StripedHtmlFormatter, self).__init__(*args, **kwargs) self.stripecount = stripecount - + def wrap(self, source, outfile): yield 0, "
" yield 0, "
"
@@ -59,19 +59,15 @@
 
         for n, i in source:
             if n == 1:
-                i = "
%s
" % \ - (parity.next(), i) + i = "
%s
" % (parity.next(), i) yield n, i yield 0, "
" yield 0, "
" -def pygments_format(filename, rawtext, - forcetext=False, - stripecount=1, +def pygments_format(filename, rawtext, forcetext=False, stripecount=1, style='colorful'): - if not forcetext: try: lexer = guess_lexer_for_filename(filename, rawtext) @@ -79,18 +75,15 @@ lexer = TextLexer() else: lexer = TextLexer() - - formatter = StripedHtmlFormatter(stripecount, - style=style, + + formatter = StripedHtmlFormatter(stripecount, style=style, linenos='inline') return highlight(rawtext, lexer, formatter) -""" -This reimplements hgweb.filerevision to use syntax highlighting -""" def filerevision_pygments(self, fctx): + """Reimplement hgweb.filerevision to use syntax highlighting""" filename = fctx.path() rawtext = fctx.data() @@ -108,7 +101,6 @@ mt = mt or 'text/plain' forcetext = False - def lines(text): for line in text.splitlines(True): yield {"line": line} @@ -120,7 +112,7 @@ stripecount=self.stripecount, style=style)) - # override per-line template + # override per-line template self.t.cache['fileline'] = '#line#' # append a to the syntax highlighting css @@ -129,7 +121,6 @@ new_header = old_header + SYNTAX_CSS self.t.cache['header'] = new_header - yield self.t("filerevision", file=filename, path=hgweb_mod._up(filename), # fixme: make public @@ -147,6 +138,7 @@ fctx.filenode()), permissions=fctx.manifest().flags(filename)) + # monkeypatch in the new version # should be safer than overriding the method in a derived class # and then patching the class