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:
Mark Lodato
2011-07-06 22:47:32 -04:00
parent 94aab04ecb
commit b9279ca1e3
2 changed files with 5 additions and 2 deletions
+3 -1
View File
@@ -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')
+2 -1
View File
@@ -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