mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #1790 literalinclude strips empty lines at the head and tail
This commit is contained in:
parent
aa66e7860b
commit
64d2f22eb4
1
CHANGES
1
CHANGES
@ -7,6 +7,7 @@ Bugs fixed
|
||||
* #1788: graphviz extension raises exception when caption option is present.
|
||||
* #1789: ``:pyobject:`` option of ``literalinclude`` directive includes following
|
||||
lines after class definitions
|
||||
* #1790: ``literalinclude`` strips empty lines at the head and tail
|
||||
|
||||
|
||||
Release 1.3.1 (released Mar 17, 2015)
|
||||
|
@ -302,15 +302,6 @@ class LiteralInclude(Directive):
|
||||
res.append(line)
|
||||
lines = res
|
||||
|
||||
if 'lineno-match' in self.options:
|
||||
# handle that docutils remove preceding lines which only contains
|
||||
# line separation.
|
||||
for line in lines:
|
||||
# check if line contains anything else than line separation.
|
||||
if line and line.splitlines()[0]:
|
||||
break
|
||||
linenostart += 1
|
||||
|
||||
prepend = self.options.get('prepend')
|
||||
if prepend:
|
||||
lines.insert(0, prepend + '\n')
|
||||
|
@ -35,12 +35,12 @@ from pygments.util import ClassNotFound
|
||||
from sphinx.pygments_styles import SphinxStyle, NoneStyle
|
||||
|
||||
lexers = dict(
|
||||
none = TextLexer(),
|
||||
python = PythonLexer(),
|
||||
pycon = PythonConsoleLexer(),
|
||||
pycon3 = PythonConsoleLexer(python3=True),
|
||||
rest = RstLexer(),
|
||||
c = CLexer(),
|
||||
none = TextLexer(stripnl=False),
|
||||
python = PythonLexer(stripnl=False),
|
||||
pycon = PythonConsoleLexer(stripnl=False),
|
||||
pycon3 = PythonConsoleLexer(python3=True, stripnl=False),
|
||||
rest = RstLexer(stripnl=False),
|
||||
c = CLexer(stripnl=False),
|
||||
)
|
||||
for _lexer in lexers.values():
|
||||
_lexer.add_filter('raiseonerror')
|
||||
|
@ -1542,7 +1542,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
# most probably a parsed-literal block -- don't highlight
|
||||
self.body.append('\\begin{alltt}\n')
|
||||
else:
|
||||
code = node.astext().rstrip('\n')
|
||||
code = node.astext()
|
||||
lang = self.hlsettingstack[-1][0]
|
||||
linenos = code.count('\n') >= self.hlsettingstack[-1][1] - 1
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
@ -1573,7 +1573,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.table.has_verbatim = True
|
||||
# get consistent trailer
|
||||
hlcode = hlcode.rstrip()[:-14] # strip \end{Verbatim}
|
||||
hlcode = hlcode.rstrip() + '\n'
|
||||
self.body.append('\n' + hlcode + '\\end{%sVerbatim}\n' %
|
||||
(self.table and 'Original' or ''))
|
||||
raise nodes.SkipNode
|
||||
|
3
tests/roots/test-directive-code/empty.inc
Normal file
3
tests/roots/test-directive-code/empty.inc
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
|
@ -15,3 +15,6 @@ Literal Includes with Line Numbers Matching
|
||||
:language: python
|
||||
:start-after: pass
|
||||
:lineno-match:
|
||||
|
||||
.. literalinclude:: empty.inc
|
||||
:lineno-match:
|
||||
|
@ -158,6 +158,7 @@ def test_literal_include_lineno_match(app, status, warning):
|
||||
|
||||
lines = (
|
||||
'<td class="linenos"><div class="linenodiv"><pre>'
|
||||
'5\n'
|
||||
'6\n'
|
||||
'7\n'
|
||||
'8\n'
|
||||
@ -166,6 +167,7 @@ def test_literal_include_lineno_match(app, status, warning):
|
||||
|
||||
start_after = (
|
||||
'<td class="linenos"><div class="linenodiv"><pre>'
|
||||
' 8\n'
|
||||
' 9\n'
|
||||
'10\n'
|
||||
'11\n'
|
||||
@ -175,6 +177,19 @@ def test_literal_include_lineno_match(app, status, warning):
|
||||
assert start_after in html
|
||||
|
||||
|
||||
@with_app('latex', testroot='directive-code')
|
||||
def test_literalinclude_file_whole_of_emptyline(app, status, warning):
|
||||
app.builder.build_all()
|
||||
latex = (app.outdir / 'Python.tex').text()
|
||||
includes = (
|
||||
'\\begin{Verbatim}[commandchars=\\\\\\{\\},numbers=left,firstnumber=1,stepnumber=1]\n'
|
||||
'\n'
|
||||
'\n'
|
||||
'\n'
|
||||
'\\end{Verbatim}\n')
|
||||
assert includes in latex
|
||||
|
||||
|
||||
@with_app('html', testroot='directive-code')
|
||||
def test_literalinclude_caption_html(app, status, warning):
|
||||
app.builder.build('index')
|
||||
|
Loading…
Reference in New Issue
Block a user