mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
When highlighting Python code, ignore extra indentation before
trying to parse it as Python.
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -1,6 +1,9 @@
|
||||
Release 0.6.2 (in development)
|
||||
==============================
|
||||
|
||||
* When highlighting Python code, ignore extra indentation before
|
||||
trying to parse it as Python.
|
||||
|
||||
* #191: Don't escape the tilde in URIs in LaTeX.
|
||||
|
||||
* Don't consider contents of source comments for the search index.
|
||||
|
@@ -13,6 +13,7 @@ import sys
|
||||
import cgi
|
||||
import re
|
||||
import parser
|
||||
import textwrap
|
||||
|
||||
from sphinx.util.texescape import tex_hl_escape_map
|
||||
|
||||
@@ -129,6 +130,10 @@ class PygmentsBridge(object):
|
||||
# Make sure it ends in a newline
|
||||
src += '\n'
|
||||
|
||||
# Ignore consistent indentation.
|
||||
if src.lstrip('\n').startswith(' '):
|
||||
src = textwrap.dedent(src)
|
||||
|
||||
# Replace "..." by a mark which is also a valid python expression
|
||||
# (Note, the highlighter gets the original source, this is only done
|
||||
# to allow "..." in code and still highlight it as Python code.)
|
||||
|
@@ -1,3 +1,10 @@
|
||||
Testing downloadable files
|
||||
==========================
|
||||
|
||||
Download :download:`img.png` here.
|
||||
Download :download:`this <subdir/img.png>` there.
|
||||
Don't download :download:`this <nonexisting.png>`.
|
||||
|
||||
Test file and literal inclusion
|
||||
===============================
|
||||
|
||||
@@ -37,10 +44,10 @@ Literalinclude options
|
||||
:start-after: coding: utf-8
|
||||
:end-before: class Foo
|
||||
|
||||
Test if dedenting before parsing works.
|
||||
|
||||
Testing downloadable files
|
||||
==========================
|
||||
.. highlight:: python
|
||||
|
||||
Download :download:`img.png` here.
|
||||
Download :download:`this <subdir/img.png>` there.
|
||||
Don't download :download:`this <nonexisting.png>`.
|
||||
.. cssclass:: inc-pyobj-dedent
|
||||
.. literalinclude:: literal.inc
|
||||
:pyobject: Bar.baz
|
||||
|
@@ -43,7 +43,7 @@ ENV_WARNINGS = """\
|
||||
http://www.python.org/logo.png
|
||||
%(root)s/includes.txt:: (WARNING/2) Encoding 'utf-8-sig' used for reading \
|
||||
included file u'wrongenc.inc' seems to be wrong, try giving an :encoding: option
|
||||
%(root)s/includes.txt:56: WARNING: download file not readable: nonexisting.png
|
||||
%(root)s/includes.txt:4: WARNING: download file not readable: nonexisting.png
|
||||
"""
|
||||
|
||||
HTML_WARNINGS = ENV_WARNINGS + """\
|
||||
@@ -134,6 +134,8 @@ if pygments:
|
||||
r'^class Foo:\n pass\nclass Bar:\n$',
|
||||
".//div[@class='inc-startend highlight-text']/div/pre":
|
||||
ur'^foo = u"Including Unicode characters: üöä"\n$',
|
||||
".//div[@class='inc-pyobj-dedent highlight-python']/div/pre/span":
|
||||
r'def',
|
||||
})
|
||||
HTML_XPATH['subdir/includes.html'].update({
|
||||
".//pre/span": 'line 1',
|
||||
|
Reference in New Issue
Block a user