Fix #2253: `:pyobject: option of literalinclude` directive can't detect indented body block when the block starts with blank or comment lines.

This commit is contained in:
shimizukawa 2016-01-20 22:48:16 +09:00
parent e89d8777f2
commit 0f2e62db24
5 changed files with 62 additions and 1 deletions

View File

@ -14,6 +14,8 @@ Bugs fixed
that contains regular-expression like string
* #1565: Show warning if Pygments throws an ErrorToken
* #2211: Fix paragraphs in table cell doesn't work in Latex output
* #2253: ``:pyobject:`` option of ``literalinclude`` directive can't detect indented
body block when the block starts with blank or comment lines.
Release 1.3.4 (released Jan 12, 2016)
=====================================

View File

@ -300,7 +300,7 @@ class ModuleAnalyzer(object):
yield tokentup
tokeniter = tokeniter()
for type, tok, spos, epos, line in tokeniter:
if expect_indent:
if expect_indent and type != token.NL:
if type != token.INDENT:
# no suite -- one-line definition
assert stack

View File

@ -0,0 +1,13 @@
===========================
Literal Includes for python
===========================
block start with blank or comment
=================================
.. literalinclude:: target.py
:pyobject: block_start_with_comment
.. literalinclude:: target.py
:pyobject: block_start_with_blank

View File

@ -0,0 +1,22 @@
# Literally included file using Python highlighting
# -*- coding: utf-8 -*-
foo = "Including Unicode characters: üöä"
class Foo:
pass
class Bar:
def baz():
pass
# comment after Bar class definition
def bar(): pass
def block_start_with_comment():
# Comment
return 1
def block_start_with_blank():
return 1

View File

@ -98,6 +98,30 @@ def test_literal_include_dedent(app, status, warning):
assert blocks[5].text == '\n\n' # dedent: 1000
@with_app('xml', testroot='directive-code')
def test_literal_include_block_start_with_comment_or_brank(app, status, warning):
app.builder.build(['python'])
et = ElementTree.parse(app.outdir / 'python.xml')
secs = et.findall('./section/section')
literal_include = secs[0].findall('literal_block')
assert len(literal_include) > 0
actual = literal_include[0].text
expect = (
'def block_start_with_comment():\n'
' # Comment\n'
' return 1\n'
)
assert actual == expect
actual = literal_include[1].text
expect = (
'def block_start_with_blank():\n'
'\n'
' return 1\n'
)
assert actual == expect
@with_app('html', testroot='directive-code')
def test_literal_include_linenos(app, status, warning):
app.builder.build(['linenos'])