@@ -376,10 +376,16 @@ def convert_figcaption(self, el, text, convert_as_inline):
376
376
return '\n \n ' + text + '\n \n '
377
377
378
378
def convert_td (self , el , text , convert_as_inline ):
379
- return ' ' + text .strip ().replace ("\n " , " " ) + ' |'
379
+ colspan = 1
380
+ if 'colspan' in el .attrs :
381
+ colspan = int (el ['colspan' ])
382
+ return ' ' + text .strip ().replace ("\n " , " " ) + ' |' * colspan
380
383
381
384
def convert_th (self , el , text , convert_as_inline ):
382
- return ' ' + text + ' |'
385
+ colspan = 1
386
+ if 'colspan' in el .attrs :
387
+ colspan = int (el ['colspan' ])
388
+ return ' ' + text .strip ().replace ("\n " , " " ) + ' |' * colspan
383
389
384
390
def convert_tr (self , el , text , convert_as_inline ):
385
391
cells = el .find_all (['td' , 'th' ])
@@ -392,7 +398,13 @@ def convert_tr(self, el, text, convert_as_inline):
392
398
underline = ''
393
399
if is_headrow and not el .previous_sibling :
394
400
# first row and is headline: print headline underline
395
- underline += '| ' + ' | ' .join (['---' ] * len (cells )) + ' |' + '\n '
401
+ full_colspan = 0
402
+ for cell in cells :
403
+ if "colspan" in cell .attrs :
404
+ full_colspan += int (cell ["colspan" ])
405
+ else :
406
+ full_colspan += 1
407
+ underline += '| ' + ' | ' .join (['---' ] * full_colspan ) + ' |' + '\n '
396
408
elif (not el .previous_sibling
397
409
and (el .parent .name == 'table'
398
410
or (el .parent .name == 'tbody'
0 commit comments