mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Allow lexer guessing.
This commit is contained in:
parent
1dec332ff9
commit
d97f2a2c58
3
CHANGES
3
CHANGES
@ -66,6 +66,9 @@ New features added
|
|||||||
HTML, LaTeX and text translators; this prevents having to manually
|
HTML, LaTeX and text translators; this prevents having to manually
|
||||||
patch the classes.
|
patch the classes.
|
||||||
|
|
||||||
|
* Exposed Pygments' lexer guessing as a highlight "language"
|
||||||
|
``guess``.
|
||||||
|
|
||||||
* Added ``Sphinx.add_javascript()`` that adds scripts to load in the
|
* Added ``Sphinx.add_javascript()`` that adds scripts to load in the
|
||||||
default HTML template.
|
default HTML template.
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ try:
|
|||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
from pygments.lexers import PythonLexer, PythonConsoleLexer, CLexer, \
|
from pygments.lexers import PythonLexer, PythonConsoleLexer, CLexer, \
|
||||||
TextLexer, RstLexer
|
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.formatters import HtmlFormatter, LatexFormatter
|
||||||
from pygments.filters import ErrorToken
|
from pygments.filters import ErrorToken
|
||||||
from pygments.style import Style
|
from pygments.style import Style
|
||||||
@ -157,6 +157,11 @@ class PygmentsBridge(object):
|
|||||||
elif lang in ('python3', 'py3') and source.startswith('>>>'):
|
elif lang in ('python3', 'py3') and source.startswith('>>>'):
|
||||||
# for py3, recognize interactive sessions, but do not try parsing...
|
# for py3, recognize interactive sessions, but do not try parsing...
|
||||||
lexer = lexers['pycon3']
|
lexer = lexers['pycon3']
|
||||||
|
elif lang == 'guess':
|
||||||
|
try:
|
||||||
|
lexer = guess_lexer(source)
|
||||||
|
except Exception:
|
||||||
|
return self.unhighlighted(source)
|
||||||
else:
|
else:
|
||||||
if lang in lexers:
|
if lang in lexers:
|
||||||
lexer = lexers[lang]
|
lexer = lexers[lang]
|
||||||
|
Loading…
Reference in New Issue
Block a user