Georg Brandl avatar Georg Brandl committed c06adee

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

Comments (0)

Files changed (2)

 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
   the system directory on Unix systems.
 

sphinx/writers/latex.py

         self.bibitems = []
         self.table = None
         self.next_table_colspec = None
-        self.highlightlang = builder.config.highlight_language
-        self.highlightlinenothreshold = sys.maxint
+        # stack of [language, linenothreshold] settings per file
+        # 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.footnotestack = []
         self.curfilestack = []
         self.body.append('\\hypertarget{--doc-%s}{}' %
                          self.idescape(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):
         fnotes = {}
     def depart_start_of_file(self, node):
         self.footnotestack.pop()
         self.curfilestack.pop()
+        self.hlsettingstack.pop()
 
     def visit_highlightlang(self, node):
-        self.highlightlang = node['lang']
-        self.highlightlinenothreshold = node['linenothreshold']
+        self.hlsettingstack[-1] = [node['lang'], node['linenothreshold']]
         raise nodes.SkipNode
 
     def visit_section(self, node):
         self.verbatim = ''
     def depart_literal_block(self, node):
         code = self.verbatim.rstrip('\n')
-        lang = self.highlightlang
-        linenos = code.count('\n') >= self.highlightlinenothreshold - 1
+        lang = self.hlsettingstack[-1][0]
+        linenos = code.count('\n') >= self.hlsettingstack[-1][1] - 1
         if node.has_key('language'):
             # code-block directives
             lang = node['language']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.