Commits

Mark Lodato committed 4d6e40d

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.

Comments (0)

Files changed (2)

sphinx/writers/html.py

             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')

sphinx/writers/latex.py

             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