From 5783c8a93b72d232b21bf3d7da7aa676306ef763 Mon Sep 17 00:00:00 2001 From: itmammoth Date: Sat, 8 Feb 2025 13:30:15 +0900 Subject: [PATCH 1/3] Support `video` tag with `poster` attribute --- markdownify/__init__.py | 13 +++++++++++++ tests/test_conversions.py | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 9e4c99f..a883db0 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -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 + def convert_list(self, el, text, convert_as_inline): # Converting a list to inline is undefined. diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 1739cb9..0d14c78 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -242,6 +242,12 @@ def test_img(): assert md('Alt text') == '![Alt text](/path/to/img.jpg)' +def test_video(): + assert md('