Mercurial > genshi > genshi-test
diff setup.py @ 508:cabd80e75dad
Enable syntax highlighting (with Pygments) on doc page.
author | cmlenz |
---|---|
date | Wed, 06 Jun 2007 10:06:29 +0000 |
parents | 460b1f0db935 |
children | f38ce008ab0a |
line wrap: on
line diff
--- a/setup.py +++ b/setup.py @@ -35,9 +35,29 @@ def run(self): from docutils.core import publish_cmdline + from docutils.nodes import raw + from docutils.parsers import rst + docutils_conf = os.path.join('doc', 'docutils.conf') epydoc_conf = os.path.join('doc', 'epydoc.conf') + try: + from pygments import highlight + from pygments.lexers import get_lexer_by_name + from pygments.formatters import HtmlFormatter + + def code_block(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + lexer = get_lexer_by_name(arguments[0]) + html = highlight('\n'.join(content), lexer, HtmlFormatter()) + return [raw('', html, format='html')] + code_block.arguments = (1, 0, 0) + code_block.options = {'language' : rst.directives.unchanged} + code_block.content = 1 + rst.directives.register_directive('code-block', code_block) + except ImportError: + print 'Pygments not installed, syntax highlighting disabled' + for source in glob('doc/*.txt'): dest = os.path.splitext(source)[0] + '.html' if not os.path.exists(dest) or \ @@ -58,7 +78,6 @@ ] cli.cli() sys.argv[1:] = old_argv - except ImportError: print 'epydoc not installed, skipping API documentation.'