@@ -106,6 +106,7 @@ def should_remove_whitespace_inside(el):
106
106
return el .name in ('p' , 'blockquote' ,
107
107
'article' , 'div' , 'section' ,
108
108
'ol' , 'ul' , 'li' ,
109
+ 'dl' , 'dt' , 'dd' ,
109
110
'table' , 'thead' , 'tbody' , 'tfoot' ,
110
111
'tr' , 'td' , 'th' )
111
112
@@ -442,7 +443,7 @@ def _indent_for_blockquote(match):
442
443
443
444
def convert_br (self , el , text , parent_tags ):
444
445
if '_inline' in parent_tags :
445
- return ""
446
+ return ' '
446
447
447
448
if self .options ['newline_style' ].lower () == BACKSLASH :
448
449
return '\\ \n '
@@ -489,6 +490,11 @@ def _indent_for_dd(match):
489
490
490
491
return '%s\n ' % text
491
492
493
+ # definition lists are formatted as follows:
494
+ # https://pandoc.org/MANUAL.html#definition-lists
495
+ # https://michelf.ca/projects/php-markdown/extra/#def-list
496
+ convert_dl = convert_div
497
+
492
498
def convert_dt (self , el , text , parent_tags ):
493
499
# remove newlines from term text
494
500
text = (text or '' ).strip ()
@@ -501,7 +507,7 @@ def convert_dt(self, el, text, parent_tags):
501
507
# TODO - format consecutive <dt> elements as directly adjacent lines):
502
508
# https://michelf.ca/projects/php-markdown/extra/#def-list
503
509
504
- return '\n %s\n ' % text
510
+ return '\n \n %s\n ' % text
505
511
506
512
def _convert_hn (self , n , el , text , parent_tags ):
507
513
""" Method name prefixed with _ to prevent <hn> to call this """
@@ -538,6 +544,24 @@ def convert_img(self, el, text, parent_tags):
538
544
539
545
return '' % (alt , src , title_part )
540
546
547
+ def convert_video (self , el , text , parent_tags ):
548
+ if ('_inline' in parent_tags
549
+ and el .parent .name not in self .options ['keep_inline_images_in' ]):
550
+ return text
551
+ src = el .attrs .get ('src' , None ) or ''
552
+ if not src :
553
+ sources = el .find_all ('source' , attrs = {'src' : True })
554
+ if sources :
555
+ src = sources [0 ].attrs .get ('src' , None ) or ''
556
+ poster = el .attrs .get ('poster' , None ) or ''
557
+ if src and poster :
558
+ return '[](%s)' % (text , poster , src )
559
+ if src :
560
+ return '[%s](%s)' % (text , src )
561
+ if poster :
562
+ return '' % (text , poster )
563
+ return text
564
+
541
565
def convert_list (self , el , text , parent_tags ):
542
566
543
567
# Converting a list to inline is undefined.
@@ -677,6 +701,12 @@ def convert_tr(self, el, text, parent_tags):
677
701
)
678
702
overline = ''
679
703
underline = ''
704
+ full_colspan = 0
705
+ for cell in cells :
706
+ if 'colspan' in cell .attrs and cell ['colspan' ].isdigit ():
707
+ full_colspan += int (cell ["colspan" ])
708
+ else :
709
+ full_colspan += 1
680
710
if ((is_headrow
681
711
or (is_head_row_missing
682
712
and self .options ['table_infer_header' ]))
@@ -685,12 +715,6 @@ def convert_tr(self, el, text, parent_tags):
685
715
# - is headline or
686
716
# - headline is missing and header inference is enabled
687
717
# print headline underline
688
- full_colspan = 0
689
- for cell in cells :
690
- if 'colspan' in cell .attrs and cell ['colspan' ].isdigit ():
691
- full_colspan += int (cell ["colspan" ])
692
- else :
693
- full_colspan += 1
694
718
underline += '| ' + ' | ' .join (['---' ] * full_colspan ) + ' |' + '\n '
695
719
elif ((is_head_row_missing
696
720
and not self .options ['table_infer_header' ])
@@ -703,8 +727,8 @@ def convert_tr(self, el, text, parent_tags):
703
727
# - the parent is table or
704
728
# - the parent is tbody at the beginning of a table.
705
729
# print empty headline above this row
706
- overline += '| ' + ' | ' .join (['' ] * len ( cells ) ) + ' |' + '\n '
707
- overline += '| ' + ' | ' .join (['---' ] * len ( cells ) ) + ' |' + '\n '
730
+ overline += '| ' + ' | ' .join (['' ] * full_colspan ) + ' |' + '\n '
731
+ overline += '| ' + ' | ' .join (['---' ] * full_colspan ) + ' |' + '\n '
708
732
return overline + '|' + text + '\n ' + underline
709
733
710
734
0 commit comments