[Python-checkins] r66481 - in doctools/trunk: CHANGES sphinx/highlighting.py

georg.brandl python-checkins at python.org
Tue Sep 16 09:49:27 CEST 2008


Author: georg.brandl
Date: Tue Sep 16 09:49:27 2008
New Revision: 66481
Log:
Allow lexer guessing.
Modified:
 doctools/trunk/CHANGES
 doctools/trunk/sphinx/highlighting.py
Modified: doctools/trunk/CHANGES
==============================================================================
--- doctools/trunk/CHANGES	(original)
+++ doctools/trunk/CHANGES	Tue Sep 16 09:49:27 2008
@@ -66,6 +66,9 @@
 HTML, LaTeX and text translators; this prevents having to manually
 patch the classes.
 
+* Exposed Pygments' lexer guessing as a highlight "language"
+ ``guess``.
+
 * Added ``Sphinx.add_javascript()`` that adds scripts to load in the
 default HTML template.
 
Modified: doctools/trunk/sphinx/highlighting.py
==============================================================================
--- doctools/trunk/sphinx/highlighting.py	(original)
+++ doctools/trunk/sphinx/highlighting.py	Tue Sep 16 09:49:27 2008
@@ -21,7 +21,7 @@
 from pygments import highlight
 from pygments.lexers import PythonLexer, PythonConsoleLexer, CLexer, \
 TextLexer, RstLexer
- from pygments.lexers import get_lexer_by_name
+ from pygments.lexers import get_lexer_by_name, guess_lexer
 from pygments.formatters import HtmlFormatter, LatexFormatter
 from pygments.filters import ErrorToken
 from pygments.style import Style
@@ -157,6 +157,11 @@
 elif lang in ('python3', 'py3') and source.startswith('>>>'):
 # for py3, recognize interactive sessions, but do not try parsing...
 lexer = lexers['pycon3']
+ elif lang == 'guess':
+ try:
+ lexer = guess_lexer(source)
+ except Exception:
+ return self.unhighlighted(source)
 else:
 if lang in lexers:
 lexer = lexers[lang]


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /