mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
parent
e89d8777f2
commit
0f2e62db24
2
CHANGES
2
CHANGES
@ -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)
|
||||
=====================================
|
||||
|
@ -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
|
||||
|
13
tests/roots/test-directive-code/python.rst
Normal file
13
tests/roots/test-directive-code/python.rst
Normal 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
|
||||
|
22
tests/roots/test-directive-code/target.py
Normal file
22
tests/roots/test-directive-code/target.py
Normal 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
|
@ -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'])
|
||||
|
Loading…
Reference in New Issue
Block a user