@@ -3379,7 +3379,7 @@ def run(self, text):
33793379 (?:
33803380 ^[ ]{0,%d}(?!\ ) # ensure line begins with 0 to less_than_tab spaces
33813381 .*\|.*[ ]*\n
3382- )+
3382+ )*
33833383 )
33843384 ''' % (less_than_tab , less_than_tab , less_than_tab ), re .M | re .X )
33853385 return table_re .sub (self .sub , text )
@@ -3415,17 +3415,19 @@ def sub(self, match: re.Match) -> str:
34153415 hlines .append ('</thead>' )
34163416
34173417 # tbody
3418- hlines .append ('<tbody>' )
3419- for line in body .strip ('\n ' ).split ('\n ' ):
3420- hlines .append ('<tr>' )
3421- 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 )))]
3422- for col_idx , col in enumerate (cols ):
3423- hlines .append (' <td{}>{}</td>' .format (
3424- align_from_col_idx .get (col_idx , '' ),
3425- self .md ._run_span_gamut (col )
3426- ))
3427- hlines .append ('</tr>' )
3428- hlines .append ('</tbody>' )
3418+ body = body .strip ('\n ' )
3419+ if body :
3420+ hlines .append ('<tbody>' )
3421+ for line in body .split ('\n ' ):
3422+ hlines .append ('<tr>' )
3423+ 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 )))]
3424+ for col_idx , col in enumerate (cols ):
3425+ hlines .append (' <td{}>{}</td>' .format (
3426+ align_from_col_idx .get (col_idx , '' ),
3427+ self .md ._run_span_gamut (col )
3428+ ))
3429+ hlines .append ('</tr>' )
3430+ hlines .append ('</tbody>' )
34293431 hlines .append ('</table>' )
34303432
34313433 return '\n ' .join (hlines ) + '\n '
0 commit comments