mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
add 'highlight_args' option for literal_block nodes
For the HTML and LaTeX writers, if 'highlight_args' is set on a literal_block node, this is taken as a dictionary of keyword arguments to pass to PygmentsBridge.highlight_block. This allows custom directives to directly set formatter options.
This commit is contained in:
@@ -238,10 +238,12 @@ class HTMLTranslator(BaseTranslator):
|
||||
lang = node['language']
|
||||
if node.has_key('linenos'):
|
||||
linenos = node['linenos']
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
def warner(msg):
|
||||
self.builder.warn(msg, (self.builder.current_docname, node.line))
|
||||
highlighted = self.highlighter.highlight_block(
|
||||
node.rawsource, lang, warn=warner, linenos=linenos)
|
||||
node.rawsource, lang, warn=warner, linenos=linenos,
|
||||
**highlight_args)
|
||||
starttag = self.starttag(node, 'div', suffix='',
|
||||
CLASS='highlight-%s' % lang)
|
||||
self.body.append(starttag + highlighted + '</div>\n')
|
||||
|
||||
@@ -1265,10 +1265,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
lang = node['language']
|
||||
if 'linenos' in node:
|
||||
linenos = node['linenos']
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
def warner(msg):
|
||||
self.builder.warn(msg, (self.curfilestack[-1], node.line))
|
||||
hlcode = self.highlighter.highlight_block(code, lang, warn=warner,
|
||||
linenos=linenos)
|
||||
linenos=linenos, **highlight_args)
|
||||
# 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