hgext/highlight.py
changeset 6485 938319418d8c
parent 6394 55bc0a035e1f
child 6511 5c1bb5750558
--- a/hgext/highlight.py	Sat Apr 05 19:33:34 2008 +0200
+++ b/hgext/highlight.py	Sat Apr 05 21:29:02 2008 +0200
@@ -15,10 +15,7 @@
 [web]
 pygments_style = <style>
 
-The default is 'colorful'.  If this is changed the corresponding CSS
-file should be re-generated by running
-
-# pygmentize -f html -S <newstyle>
+The default is 'colorful'.
 
 -- Adam Hupp <adam@hupp.org>
 """
@@ -26,7 +23,7 @@
 from mercurial import demandimport
 demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__',])
 
-from mercurial.hgweb import webcommands, webutil
+from mercurial.hgweb import webcommands, webutil, common
 from mercurial import util
 from mercurial.templatefilters import filters
 
@@ -35,7 +32,7 @@
 from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
 from pygments.formatters import HtmlFormatter
 
-SYNTAX_CSS = ('\n<link rel="stylesheet" href="#staticurl#highlight.css" '
+SYNTAX_CSS = ('\n<link rel="stylesheet" href="{url}highlightcss" '
               'type="text/css" />')
 
 def pygmentize(field, fctx, style, tmpl):
@@ -88,7 +85,16 @@
     pygmentize('annotateline', fctx, style, tmpl)
     return web_annotate(web, req, tmpl)
 
+def generate_css(web, req, tmpl):
+    pg_style = web.config('web', 'pygments_style', 'colorful')
+    fmter = HtmlFormatter(style = pg_style)
+    req.respond(common.HTTP_OK, 'text/css')
+    return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')]
+
+
 # monkeypatch in the new version
 
 webcommands._filerevision = filerevision_highlight
 webcommands.annotate = annotate_highlight
+webcommands.highlightcss = generate_css
+webcommands.__all__.append('highlightcss')