Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,19 @@ def convert_img(self, el, text, convert_as_inline):

return '![%s](%s%s)' % (alt, src, title_part)

def convert_video(self, el, text, convert_as_inline):
# `text` is a fallback for browsers that do not support video, so it's unused
src = el.attrs.get('src', None) or ''
poster = el.attrs.get('poster', None) or ''
if (convert_as_inline
and el.parent.name not in self.options['keep_inline_images_in']):
return ''
if not poster:
return ''
if src:
return '[![](%s)](%s)' % (poster, src)
return '![](%s)' % poster
Comment thread
AlexVonB marked this conversation as resolved.
Outdated

def convert_list(self, el, text, convert_as_inline):

# Converting a list to inline is undefined.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ def test_img():
assert md('<img src="/path/to/img.jpg" alt="Alt text" />') == '![Alt text](/path/to/img.jpg)'


def test_video():
assert md('<video src="/path/to/video.mp4" poster="/path/to/img.jpg" />') == '[![](/path/to/img.jpg)](/path/to/video.mp4)'
assert md('<video poster="/path/to/img.jpg" />') == '![](/path/to/img.jpg)'
assert md('<video poster="/path/to/img.jpg">Fallback text</video>') == '![](/path/to/img.jpg)'


def test_kbd():
inline_tests('kbd', '`')

Expand Down