Re: Patches for html5_polyglot video support

Agathe Porte <[email protected]>
Newsgroups gmane.text.docutils.devel
Message-ID <[email protected]>
Attached are the patches I forgot to join.

24/05/2022 18:20, Agathe Porte :
> Hi,
>
> As discussed in docutils-users, please find attached two patches to 
> improve docutils video support. Please let me know when they are 
> merged (I see last revision is from 2021-11-23). I will send other 
> patches to improve video support further while trying to keep the 
> "image" node.
>
> Bests,
>
> Agata.
>
0002-feat-html5_polyglot-allow-alt_sources-for-video.patch (text/x-patch, 2.1 KB)
From 2532bc971163fcabe2e743e32fdcdd7ff017156e Mon Sep 17 00:00:00 2001
From: Agathe Porte <[email protected]>
Date: Tue, 3 May 2022 09:10:30 +0200
Subject: [PATCH 2/2] feat(html5_polyglot): allow alt_sources for video

---
 docutils/writers/html5_polyglot/__init__.py | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/docutils/writers/html5_polyglot/__init__.py b/docutils/writers/html5_polyglot/__init__.py
index d72fe37..bf49417 100644
--- a/docutils/writers/html5_polyglot/__init__.py
+++ b/docutils/writers/html5_polyglot/__init__.py
@@ -275,6 +275,7 @@ class HTMLTranslator(_html_base.HTMLTranslator):
         mimetype = mimetypes.guess_type(uri)[0]
         if mimetype not in self.videotypes:
             return super().visit_image(node)
+        sources = [(uri, mimetype)]
         # image size
         if 'width' in node:
             atts['width'] = node['width'].replace('px', '')
@@ -288,6 +289,11 @@ class HTMLTranslator(_html_base.HTMLTranslator):
             atts['autoplay'] = 'autoplay'
         if 'loop' in node['classes']:
             atts['loop'] = 'loop'
+        if 'alt_src' in node:
+            for s_uri in node['alt_src']:
+                s_mimetype = mimetypes.guess_type(s_ui)[0]
+                assert s_mimetype in videotypes
+                sources.append((s_uri, s_mimetype))
         atts['title'] = node.get('alt', uri)
         if getattr(self.settings, 'image_loading', None) == 'lazy':
             atts['loading'] = 'lazy'
@@ -298,10 +304,15 @@ class HTMLTranslator(_html_base.HTMLTranslator):
             suffix = ''
         else:
             suffix = '\n'
+
+        sources = suffix.join(
+            ['<source src="%s" type="%s"/>' % s for s in sources])
+
         self.body.append(
-            '%s<a href="%s">%s</a>%s</video>%s'
-            % (self.starttag(node, 'video', suffix, src=uri, **atts),
-               uri,
+            '%s%s%s%s%s</video>%s'
+            % (self.starttag(node, 'video', suffix, **atts),
+               sources,
+               suffix,
                node.get('alt', uri),
                suffix,
                suffix))
-- 
2.36.0
0001-feat-html5_polyglot-support-autoplay-loop-for-video.patch (text/x-patch, 1.1 KB)
From 027b5dc56eb46fa8bca006b52ad75cd88db2b1cf Mon Sep 17 00:00:00 2001
From: Agathe Porte <[email protected]>
Date: Tue, 3 May 2022 08:35:44 +0200
Subject: [PATCH 1/2] feat(html5_polyglot): support {autoplay,loop} for video

---
 docutils/writers/html5_polyglot/__init__.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/docutils/writers/html5_polyglot/__init__.py b/docutils/writers/html5_polyglot/__init__.py
index 8a632f9..d72fe37 100644
--- a/docutils/writers/html5_polyglot/__init__.py
+++ b/docutils/writers/html5_polyglot/__init__.py
@@ -284,6 +284,10 @@ class HTMLTranslator(_html_base.HTMLTranslator):
             atts['class'] = 'align-%s' % node['align']
         if 'controls' in node['classes']:
             atts['controls'] = 'controls'
+        if 'autoplay' in node['classes']:
+            atts['autoplay'] = 'autoplay'
+        if 'loop' in node['classes']:
+            atts['loop'] = 'loop'
         atts['title'] = node.get('alt', uri)
         if getattr(self.settings, 'image_loading', None) == 'lazy':
             atts['loading'] = 'lazy'
-- 
2.36.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.