1. Alessandro Pagnin
  2. sphinx


Mark Lodato  committed 1507481

PygmentsBridge: pass keyword arguments to Pygments

In Pygments.highlight_block, pass all extra keyword arguments, including
linenos, directly to the Pygments formatter. This allows custom
directives to use other Pygments features.

  • Participants
  • Parent commits e45b224
  • Branches default

Comments (0)

Files changed (4)

File sphinx/ext/viewcode.py

View file
         # construct a page name for the highlighted source
         pagename = '_modules/' + modname.replace('.', '/')
         # highlight the source using the builder's highlighter
-        highlighted = highlighter.highlight_block(code, 'python', False)
+        highlighted = highlighter.highlight_block(code, 'python', linenos=False)
         # split the code into lines
         lines = highlighted.splitlines()
         # split off wrap markup from the first line of the actual code

File sphinx/highlighting.py

View file
             return True
-    def highlight_block(self, source, lang, linenos=False, warn=None):
+    def highlight_block(self, source, lang, warn=None, **kwargs):
         if not isinstance(source, unicode):
             source = source.decode()
         if not pygments:
         # highlight via Pygments
-            formatter = self.get_formatter(linenos=bool(linenos))
+            formatter = self.get_formatter(**kwargs)
             hlsource = highlight(source, lexer, formatter)
             if self.dest == 'html':
                 return hlsource

File sphinx/writers/html.py

View file
         def warner(msg):
             self.builder.warn(msg, (self.builder.current_docname, node.line))
         highlighted = self.highlighter.highlight_block(
-            node.rawsource, lang, linenos, warn=warner)
+            node.rawsource, lang, warn=warner, linenos=linenos)
         starttag = self.starttag(node, 'div', suffix='',
                                  CLASS='highlight-%s' % lang)
         self.body.append(starttag + highlighted + '</div>\n')

File sphinx/writers/latex.py

View file
             linenos = node['linenos']
         def warner(msg):
             self.builder.warn(msg, (self.curfilestack[-1], node.line))
-        hlcode = self.highlighter.highlight_block(code, lang, linenos,
-                                                  warn=warner)
+        hlcode = self.highlighter.highlight_block(code, lang, warn=warner,
+                                                  linenos=linenos)
         # workaround for Unicode issue
         hlcode = hlcode.replace(u'€', u'@texteuro[]')
         # must use original Verbatim environment and "tabular" environment