diff --git a/markdownify/__init__.py b/markdownify/__init__.py index d946d2c..8b085d7 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -597,9 +597,9 @@ def convert_video(self, el, text, parent_tags): 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 '' + source = el.find('source', src=lambda value: value and value.strip(), recursive=False) + if source: + src = source['src'] poster = el.attrs.get('poster', None) or '' if src and poster: return '[![%s](%s)](%s)' % (text, poster, src) diff --git a/tests/test_conversions.py b/tests/test_conversions.py index c95483c..1858e4d 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -260,6 +260,13 @@ def test_video(): assert md('') == 'text' +def test_video_source_selection(): + sources = '' + assert md('') == '[Watch](movie.mp4)' + assert md('') == '[Watch](main.mp4)' + assert md('') == 'Watch' + + def test_kbd(): inline_tests('kbd', '`')