mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user