mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Closes #695: When the highlight language "python" is specified explicitly, do not try to parse the code to recognize non-Python snippets.
Thanks to Jonas Haag for the patch.
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -11,6 +11,9 @@ Release 1.1.3 (in development)
|
||||
* PR#36: Make the "bibliography to TOC" fix in LaTeX output specific to
|
||||
the document class.
|
||||
|
||||
* #695: When the highlight language "python" is specified explicitly,
|
||||
do not try to parse the code to recognize non-Python snippets.
|
||||
|
||||
|
||||
Release 1.1.2 (Nov 1, 2011) -- 1.1.1 is a silly version number anyway!
|
||||
======================================================================
|
||||
|
||||
@@ -153,7 +153,7 @@ class PygmentsBridge(object):
|
||||
else:
|
||||
return True
|
||||
|
||||
def highlight_block(self, source, lang, warn=None, **kwargs):
|
||||
def highlight_block(self, source, lang, warn=None, force=False, **kwargs):
|
||||
if not isinstance(source, unicode):
|
||||
source = source.decode()
|
||||
if not pygments:
|
||||
@@ -164,12 +164,14 @@ class PygmentsBridge(object):
|
||||
if source.startswith('>>>'):
|
||||
# interactive session
|
||||
lexer = lexers['pycon']
|
||||
else:
|
||||
elif not force:
|
||||
# maybe Python -- try parsing it
|
||||
if self.try_parse(source):
|
||||
lexer = lexers['python']
|
||||
else:
|
||||
return self.unhighlighted(source)
|
||||
else:
|
||||
lexer = lexers['python']
|
||||
elif lang in ('python3', 'py3') and source.startswith('>>>'):
|
||||
# for py3, recognize interactive sessions, but do not try parsing...
|
||||
lexer = lexers['pycon3']
|
||||
|
||||
@@ -233,12 +233,13 @@ class HTMLTranslator(BaseTranslator):
|
||||
lang = self.highlightlang
|
||||
linenos = node.rawsource.count('\n') >= \
|
||||
self.highlightlinenothreshold - 1
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
if node.has_key('language'):
|
||||
# code-block directives
|
||||
lang = node['language']
|
||||
highlight_args['force'] = True
|
||||
if node.has_key('linenos'):
|
||||
linenos = node['linenos']
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
def warner(msg):
|
||||
self.builder.warn(msg, (self.builder.current_docname, node.line))
|
||||
highlighted = self.highlighter.highlight_block(
|
||||
|
||||
@@ -1299,12 +1299,13 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
code = self.verbatim.rstrip('\n')
|
||||
lang = self.hlsettingstack[-1][0]
|
||||
linenos = code.count('\n') >= self.hlsettingstack[-1][1] - 1
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
if 'language' in node:
|
||||
# code-block directives
|
||||
lang = node['language']
|
||||
highlight_args['force'] = True
|
||||
if 'linenos' in node:
|
||||
linenos = node['linenos']
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
def warner(msg):
|
||||
self.builder.warn(msg, (self.curfilestack[-1], node.line))
|
||||
hlcode = self.highlighter.highlight_block(code, lang, warn=warner,
|
||||
|
||||
@@ -258,7 +258,7 @@ if pygments:
|
||||
r'def'),
|
||||
(".//div[@class='inc-tab3 highlight-text']//pre",
|
||||
r'-| |-'),
|
||||
(".//div[@class='inc-tab8 highlight-python']//pre",
|
||||
(".//div[@class='inc-tab8 highlight-python']//pre/span",
|
||||
r'-| |-'),
|
||||
])
|
||||
HTML_XPATH['subdir/includes.html'].extend([
|
||||
|
||||
Reference in New Issue
Block a user