summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Lodato <lodatom@gmail.com>2011-07-06 22:47:32 -0400
committerMark Lodato <lodatom@gmail.com>2011-07-06 22:47:32 -0400
commitd983b98d4ce162ba4dfa27944d6c735c9f01e3cc (patch)
tree7c934042fc5128649589de4f68c355b028c6eb8d
parente8d873ebf0be6d81a705d06547beb36f4c516e84 (diff)
downloadsphinx-d983b98d4ce162ba4dfa27944d6c735c9f01e3cc.tar.gz
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.
-rw-r--r--sphinx/writers/html.py4
-rw-r--r--sphinx/writers/latex.py3
2 files changed, 5 insertions, 2 deletions
diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py
index 26132515..90830c24 100644
--- a/sphinx/writers/html.py
+++ b/sphinx/writers/html.py
@@ -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')
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index f9eca27f..799756c6 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -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