Skip to content

Commit

Permalink
handle poor table formatting better. fixes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
ikirudennis committed Aug 10, 2017
1 parent 6b3a105 commit 6ad9e38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 9 additions & 0 deletions tests/test_github_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,12 @@ def test_github_issue_51():
result = textile.textile(test)
expect = '\t<p><a href="www.google.com.br">www.google.com.br</a></p>'
assert result == expect

def test_github_issue_52():
"""Table build without space after aligment raise a AttributeError."""
test = '|=.First Header |=. Second Header |'
result = textile.textile(test)
expect = ('\t<table>\n\t\t<tr>\n\t\t\t<td>=.First Header '
'</td>\n\t\t\t<td style="text-align:center;">Second Header </td>'
'\n\t\t</tr>\n\t</table>')
assert result == expect
16 changes: 9 additions & 7 deletions textile/objects/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ def process(self):
# as a normal center-aligned cell.
if i == 0 and row[:2] == '|=':
captionpattern = (r"^\|\=(?P<capts>{s}{a}{c})\. "
r"(?P<cap>[^\n]*)(?P<row>.*)".format(**{'s':
table_span_re_s, 'a': align_re_s, 'c': cls_re_s}))
r"(?P<cap>[^\n]*)(?P<row>.*)".format(**{
's': table_span_re_s, 'a': align_re_s,
'c': cls_re_s}))
caption_re = re.compile(captionpattern, re.S)
cmtch = caption_re.match(row)
caption = Caption(**cmtch.groupdict())
self.caption = '\n{0}'.format(caption.caption)
row = cmtch.group('row').lstrip()
if row == '':
continue
if cmtch:
caption = Caption(**cmtch.groupdict())
self.caption = '\n{0}'.format(caption.caption)
row = cmtch.group('row').lstrip()
if row == '':
continue

# Colgroup -- A colgroup row will not necessarily end with a |.
# Hence it may include the next row of actual table data.
Expand Down

0 comments on commit 6ad9e38

Please sign in to comment.