#409: Make the `highlight_language` config value work properly in the LaTeX builder.

This commit is contained in:
Georg Brandl 2010-05-22 11:07:15 +02:00
parent be23bc91da
commit 015c1c13a5
2 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,9 @@
Release 0.6.6 (in development) Release 0.6.6 (in development)
============================== ==============================
* #409: Make the ``highlight_language`` config value work properly
in the LaTeX builder.
* #418: Allow relocation of the translation JavaScript files to * #418: Allow relocation of the translation JavaScript files to
the system directory on Unix systems. the system directory on Unix systems.

View File

@ -218,8 +218,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.bibitems = [] self.bibitems = []
self.table = None self.table = None
self.next_table_colspec = None self.next_table_colspec = None
self.highlightlang = builder.config.highlight_language # stack of [language, linenothreshold] settings per file
self.highlightlinenothreshold = sys.maxint # the first item here is the default and must not be changed
# the second item is the default for the master file and can be changed
# by .. highlight:: directive in the master file
self.hlsettingstack = 2 * [[builder.config.highlight_language, sys.maxint]]
self.written_ids = set() self.written_ids = set()
self.footnotestack = [] self.footnotestack = []
self.curfilestack = [] self.curfilestack = []
@ -291,6 +294,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.body.append('\\hypertarget{--doc-%s}{}' % self.body.append('\\hypertarget{--doc-%s}{}' %
self.idescape(node['docname'])) self.idescape(node['docname']))
self.curfilestack.append(node['docname']) self.curfilestack.append(node['docname'])
# use default highlight settings for new file
self.hlsettingstack.append(self.hlsettingstack[0])
def collect_footnotes(self, node): def collect_footnotes(self, node):
fnotes = {} fnotes = {}
@ -311,10 +316,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
def depart_start_of_file(self, node): def depart_start_of_file(self, node):
self.footnotestack.pop() self.footnotestack.pop()
self.curfilestack.pop() self.curfilestack.pop()
self.hlsettingstack.pop()
def visit_highlightlang(self, node): def visit_highlightlang(self, node):
self.highlightlang = node['lang'] self.hlsettingstack[-1] = [node['lang'], node['linenothreshold']]
self.highlightlinenothreshold = node['linenothreshold']
raise nodes.SkipNode raise nodes.SkipNode
def visit_section(self, node): def visit_section(self, node):
@ -1161,8 +1166,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.verbatim = '' self.verbatim = ''
def depart_literal_block(self, node): def depart_literal_block(self, node):
code = self.verbatim.rstrip('\n') code = self.verbatim.rstrip('\n')
lang = self.highlightlang lang = self.hlsettingstack[-1][0]
linenos = code.count('\n') >= self.highlightlinenothreshold - 1 linenos = code.count('\n') >= self.hlsettingstack[-1][1] - 1
if node.has_key('language'): if node.has_key('language'):
# code-block directives # code-block directives
lang = node['language'] lang = node['language']