From 6ad9e3841fcffed79cfa736875bdd589cc0c5346 Mon Sep 17 00:00:00 2001 From: Dennis Burke Date: Wed, 9 Aug 2017 21:52:42 -0400 Subject: [PATCH] handle poor table formatting better. fixes #52 --- tests/test_github_issues.py | 9 +++++++++ textile/objects/table.py | 16 +++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/test_github_issues.py b/tests/test_github_issues.py index e50ad385..0aeba4d8 100644 --- a/tests/test_github_issues.py +++ b/tests/test_github_issues.py @@ -190,3 +190,12 @@ def test_github_issue_51(): result = textile.textile(test) expect = '\t

www.google.com.br

' 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\n\t\t\n\t\t\t\n\t\t\t' + '\n\t\t\n\t
=.First Header ' + 'Second Header
') + assert result == expect diff --git a/textile/objects/table.py b/textile/objects/table.py index f6940985..4796afce 100644 --- a/textile/objects/table.py +++ b/textile/objects/table.py @@ -38,15 +38,17 @@ def process(self): # as a normal center-aligned cell. if i == 0 and row[:2] == '|=': captionpattern = (r"^\|\=(?P{s}{a}{c})\. " - r"(?P[^\n]*)(?P.*)".format(**{'s': - table_span_re_s, 'a': align_re_s, 'c': cls_re_s})) + r"(?P[^\n]*)(?P.*)".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.