From b9279ca1e30c420c786e83fd6ef6342a0d549f46 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Wed, 6 Jul 2011 22:47:32 -0400 Subject: [PATCH] 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. --- sphinx/writers/html.py | 4 +++- sphinx/writers/latex.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 2613251551..90830c249c 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 + '\n') diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index f9eca27fb3..799756c6ae 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