diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-12-13 20:49:50 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-12-13 20:49:50 +0900 |
commit | 6dae5db9af55807de1db4067203e57dabb6ed774 (patch) | |
tree | f0b78af8766256130628bc9cd1ce97e8ce9937fb | |
parent | 07c5348a56471201b5901881b0d9d83f4823a6fd (diff) | |
download | sphinx-git-6dae5db9af55807de1db4067203e57dabb6ed774.tar.gz |
Fix SphinxRSTFileInput should expand tabs
-rw-r--r-- | sphinx/io.py | 7 | ||||
-rw-r--r-- | tests/test_io.py | 11 |
2 files changed, 15 insertions, 3 deletions
diff --git a/sphinx/io.py b/sphinx/io.py index 056c763b1..5f34b74dd 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -14,7 +14,7 @@ import codecs from docutils.io import FileInput, NullOutput from docutils.core import Publisher from docutils.readers import standalone -from docutils.statemachine import StringList +from docutils.statemachine import StringList, string2lines from docutils.writers import UnfilteredWriter from six import text_type from typing import Any, Union # NOQA @@ -195,9 +195,10 @@ class SphinxRSTFileInput(SphinxBaseFileInput): def read(self): # type: () -> StringList - data = SphinxBaseFileInput.read(self) + inputstring = SphinxBaseFileInput.read(self) + lines = string2lines(inputstring, convert_whitespace=True) content = StringList() - for lineno, line in enumerate(data.splitlines()): + for lineno, line in enumerate(lines): content.append(line, self.source_path, lineno) if self.env.config.rst_prolog: diff --git a/tests/test_io.py b/tests/test_io.py index a017a2cc0..ecd4a1009 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -105,3 +105,14 @@ def test_SphinxRSTFileInput(app): assert result.info(3) == ('<rst_epilog>', 0) assert result.info(4) == ('<rst_epilog>', 1) assert result.info(5) == ('<rst_epilog>', None) # out of range + + # expandtabs / convert whitespaces + app.env.config.rst_prolog = None + app.env.config.rst_epilog = None + text = ('\thello Sphinx world\n' + '\v\fSphinx is a document generator') + source = SphinxRSTFileInput(app, app.env, source=StringIO(text), + source_path='dummy.rst', encoding='utf-8') + result = source.read() + assert result.data == [' hello Sphinx world', + ' Sphinx is a document generator'] |