diff --git a/lib/markdown2.py b/lib/markdown2.py index 72e56327..01380593 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3379,7 +3379,7 @@ def run(self, text): (?: ^[ ]{0,%d}(?!\ ) # ensure line begins with 0 to less_than_tab spaces .*\|.*[ ]*\n - )+ + )* ) ''' % (less_than_tab, less_than_tab, less_than_tab), re.M | re.X) return table_re.sub(self.sub, text) @@ -3415,17 +3415,19 @@ def sub(self, match: re.Match) -> str: hlines.append('') # tbody - hlines.append('') - for line in body.strip('\n').split('\n'): - hlines.append('') - cols = [re.sub(escape_bar_re, '|', cell.strip()) for cell in re.split(split_bar_re, re.sub(trim_bar_re, "", re.sub(trim_space_re, "", line)))] - for col_idx, col in enumerate(cols): - hlines.append(' {}'.format( - align_from_col_idx.get(col_idx, ''), - self.md._run_span_gamut(col) - )) - hlines.append('') - hlines.append('') + body = body.strip('\n') + if body: + hlines.append('') + for line in body.split('\n'): + hlines.append('') + cols = [re.sub(escape_bar_re, '|', cell.strip()) for cell in re.split(split_bar_re, re.sub(trim_bar_re, "", re.sub(trim_space_re, "", line)))] + for col_idx, col in enumerate(cols): + hlines.append(' {}'.format( + align_from_col_idx.get(col_idx, ''), + self.md._run_span_gamut(col) + )) + hlines.append('') + hlines.append('') hlines.append('') return '\n'.join(hlines) + '\n' diff --git a/test/tm-cases/tables.html b/test/tm-cases/tables.html index 7a262d81..3f919a1e 100644 --- a/test/tm-cases/tables.html +++ b/test/tm-cases/tables.html @@ -394,3 +394,14 @@

escaping of pipes

+ +

table without rows

+ + + + + + + + +
abcdef
diff --git a/test/tm-cases/tables.text b/test/tm-cases/tables.text index 0cd4e53c..ed7512ae 100644 --- a/test/tm-cases/tables.text +++ b/test/tm-cases/tables.text @@ -156,3 +156,8 @@ the rule is it must have at least a single dash in there. | A | \| | C \| C | |--- |--- | ------ | |\|\|| BB | C | + +# table without rows + +| abc | def | +| --- | --- |