diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 5d21506..3763a49 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -538,6 +538,24 @@ def convert_img(self, el, text, parent_tags): return '![%s](%s%s)' % (alt, src, title_part) + def convert_video(self, el, text, parent_tags): + if ('_inline' in parent_tags + and el.parent.name not in self.options['keep_inline_images_in']): + return text + src = el.attrs.get('src', None) or '' + if not src: + sources = el.find_all('source', attrs={'src': True}) + if sources: + src = sources[0].attrs.get('src', None) or '' + poster = el.attrs.get('poster', None) or '' + if src and poster: + return '[![%s](%s)](%s)' % (text, poster, src) + if src: + return '[%s](%s)' % (text, src) + if poster: + return '![%s](%s)' % (text, poster) + return text + def convert_list(self, el, text, parent_tags): # Converting a list to inline is undefined. diff --git a/tests/test_conversions.py b/tests/test_conversions.py index e851ac2..b406a9f 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -243,6 +243,14 @@ def test_img(): assert md('Alt text') == '![Alt text](/path/to/img.jpg)' +def test_video(): + assert md('') == '[![text](/path/to/img.jpg)](/path/to/video.mp4)' + assert md('') == '[text](/path/to/video.mp4)' + assert md('') == '[text](/path/to/video.mp4)' + assert md('') == '![text](/path/to/img.jpg)' + assert md('') == 'text' + + def test_kbd(): inline_tests('kbd', '`')