@@ -106,6 +106,7 @@ def should_remove_whitespace_inside(el):
106106 return el .name in ('p' , 'blockquote' ,
107107 'article' , 'div' , 'section' ,
108108 'ol' , 'ul' , 'li' ,
109+ 'dl' , 'dt' , 'dd' ,
109110 'table' , 'thead' , 'tbody' , 'tfoot' ,
110111 'tr' , 'td' , 'th' )
111112
@@ -442,7 +443,7 @@ def _indent_for_blockquote(match):
442443
443444 def convert_br (self , el , text , parent_tags ):
444445 if '_inline' in parent_tags :
445- return ""
446+ return ' '
446447
447448 if self .options ['newline_style' ].lower () == BACKSLASH :
448449 return '\\ \n '
@@ -489,6 +490,11 @@ def _indent_for_dd(match):
489490
490491 return '%s\n ' % text
491492
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+
492498 def convert_dt (self , el , text , parent_tags ):
493499 # remove newlines from term text
494500 text = (text or '' ).strip ()
@@ -501,7 +507,7 @@ def convert_dt(self, el, text, parent_tags):
501507 # TODO - format consecutive <dt> elements as directly adjacent lines):
502508 # https://michelf.ca/projects/php-markdown/extra/#def-list
503509
504- return '\n %s\n ' % text
510+ return '\n \n %s\n ' % text
505511
506512 def _convert_hn (self , n , el , text , parent_tags ):
507513 """ Method name prefixed with _ to prevent <hn> to call this """
@@ -538,6 +544,24 @@ def convert_img(self, el, text, parent_tags):
538544
539545 return '' % (alt , src , title_part )
540546
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+
541565 def convert_list (self , el , text , parent_tags ):
542566
543567 # Converting a list to inline is undefined.
@@ -677,6 +701,12 @@ def convert_tr(self, el, text, parent_tags):
677701 )
678702 overline = ''
679703 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
680710 if ((is_headrow
681711 or (is_head_row_missing
682712 and self .options ['table_infer_header' ]))
@@ -685,12 +715,6 @@ def convert_tr(self, el, text, parent_tags):
685715 # - is headline or
686716 # - headline is missing and header inference is enabled
687717 # 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
694718 underline += '| ' + ' | ' .join (['---' ] * full_colspan ) + ' |' + '\n '
695719 elif ((is_head_row_missing
696720 and not self .options ['table_infer_header' ])
@@ -703,8 +727,8 @@ def convert_tr(self, el, text, parent_tags):
703727 # - the parent is table or
704728 # - the parent is tbody at the beginning of a table.
705729 # 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 '
708732 return overline + '|' + text + '\n ' + underline
709733
710734
0 commit comments