diff options
author | Georg Brandl <georg@python.org> | 2008-09-16 07:49:27 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-09-16 07:49:27 +0000 |
commit | d97f2a2c585e9eb1df69a2a8d5aeef1c998af2e0 (patch) | |
tree | e65a8ed1a896c7d1e3b40de4645ba6156c7fd82d /sphinx/highlighting.py | |
parent | 1dec332ff9e0934efb62f1adac262a2178356c1b (diff) | |
download | sphinx-git-d97f2a2c585e9eb1df69a2a8d5aeef1c998af2e0.tar.gz |
Allow lexer guessing.
Diffstat (limited to 'sphinx/highlighting.py')
-rw-r--r-- | sphinx/highlighting.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index b494b0725..1637b2c3f 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -21,7 +21,7 @@ try: 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 @@ class PygmentsBridge(object): 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] |