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.
This commit is contained in:
Mark Lodato
2011-07-06 22:05:22 -04:00
parent cab5a5edc1
commit 94aab04ecb
4 changed files with 6 additions and 6 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 + '</div>\n')

View File

@@ -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