From 94aab04ecb629430e8d61b06f643531691742e76 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Wed, 6 Jul 2011 22:05:22 -0400 Subject: [PATCH] PygmentsBridge: pass keyword arguments to Pygments In Pygments.highlight_block, pass all extra keyword arguments, including linenos, directly to the Pygments formatter. This allows custom directives to use other Pygments features. --- sphinx/ext/viewcode.py | 2 +- sphinx/highlighting.py | 4 ++-- sphinx/writers/html.py | 2 +- sphinx/writers/latex.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py index 020db6974..32840f30f 100644 --- a/sphinx/ext/viewcode.py +++ b/sphinx/ext/viewcode.py @@ -98,7 +98,7 @@ def collect_pages(app): # construct a page name for the highlighted source pagename = '_modules/' + modname.replace('.', '/') # highlight the source using the builder's highlighter - highlighted = highlighter.highlight_block(code, 'python', False) + highlighted = highlighter.highlight_block(code, 'python', linenos=False) # split the code into lines lines = highlighted.splitlines() # split off wrap markup from the first line of the actual code diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index 75c8be13a..65fe9f7d3 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -151,7 +151,7 @@ class PygmentsBridge(object): else: return True - def highlight_block(self, source, lang, linenos=False, warn=None): + def highlight_block(self, source, lang, warn=None, **kwargs): if not isinstance(source, unicode): source = source.decode() if not pygments: @@ -198,7 +198,7 @@ class PygmentsBridge(object): # highlight via Pygments try: - formatter = self.get_formatter(linenos=bool(linenos)) + formatter = self.get_formatter(**kwargs) hlsource = highlight(source, lexer, formatter) if self.dest == 'html': return hlsource diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 99d621c6f..261325155 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -241,7 +241,7 @@ class HTMLTranslator(BaseTranslator): def warner(msg): self.builder.warn(msg, (self.builder.current_docname, node.line)) highlighted = self.highlighter.highlight_block( - node.rawsource, lang, linenos, warn=warner) + node.rawsource, lang, warn=warner, linenos=linenos) starttag = self.starttag(node, 'div', suffix='', CLASS='highlight-%s' % lang) self.body.append(starttag + highlighted + '\n') diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index ccd7a8bf2..f9eca27fb 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1267,8 +1267,8 @@ class LaTeXTranslator(nodes.NodeVisitor): linenos = node['linenos'] def warner(msg): self.builder.warn(msg, (self.curfilestack[-1], node.line)) - hlcode = self.highlighter.highlight_block(code, lang, linenos, - warn=warner) + hlcode = self.highlighter.highlight_block(code, lang, warn=warner, + linenos=linenos) # workaround for Unicode issue hlcode = hlcode.replace(u'€', u'@texteuro[]') # must use original Verbatim environment and "tabular" environment