make text generate wrong table when it has empty table cells. Closes #1544

This commit is contained in:
Takayuki Shimizukawa 2014-08-26 20:52:02 +09:00
parent 8f7936d75c
commit 438f9fe3de
3 changed files with 29 additions and 2 deletions

View File

@ -39,6 +39,7 @@ Bugs fixed
* PR#281, PR#282, #1509: TODO extension not compatible with websupport. Thanks * PR#281, PR#282, #1509: TODO extension not compatible with websupport. Thanks
to Takeshi Komiya. to Takeshi Komiya.
* #1477: gettext does not extract nodes.line in a table or list. * #1477: gettext does not extract nodes.line in a table or list.
* #1544: `make text` generate wrong table when it has empty table cells.
Release 1.2.2 (released Mar 2, 2014) Release 1.2.2 (released Mar 2, 2014)
==================================== ====================================

View File

@ -11,7 +11,7 @@
import os import os
import re import re
import textwrap import textwrap
from itertools import groupby from itertools import groupby, izip_longest
from docutils import nodes, writers from docutils import nodes, writers
from docutils.utils import column_width from docutils.utils import column_width
@ -503,7 +503,7 @@ class TextTranslator(nodes.NodeVisitor):
self.add_text(''.join(out) + self.nl) self.add_text(''.join(out) + self.nl)
def writerow(row): def writerow(row):
lines = zip(*row) lines = izip_longest(*row)
for line in lines: for line in lines:
out = ['|'] out = ['|']
for i, cell in enumerate(line): for i, cell in enumerate(line):

View File

@ -139,3 +139,29 @@ def test_nonascii_maxwidth(app):
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
line_widths = [column_width(line) for line in lines] line_widths = [column_width(line) for line in lines]
assert max(line_widths) < MAXWIDTH assert max(line_widths) < MAXWIDTH
@with_text_app()
def test_table_with_empty_cell(app):
contents = (u"""
+-----+-----+
| XXX | XXX |
+-----+-----+
| | XXX |
+-----+-----+
| XXX | |
+-----+-----+
""")
(app.srcdir / 'contents.rst').write_text(contents, encoding='utf-8')
app.builder.build_all()
result = (app.outdir / 'contents.txt').text(encoding='utf-8')
lines = [line.strip() for line in result.splitlines() if line.strip()]
assert lines[0] == "+-------+-------+"
assert lines[1] == "| XXX | XXX |"
assert lines[2] == "+-------+-------+"
assert lines[3] == "| | XXX |"
assert lines[4] == "+-------+-------+"
assert lines[5] == "| XXX | |"
assert lines[6] == "+-------+-------+"