mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Regex embedded mp4/webm/mp3 files out of <img> and into <video> or <audio> tags
This commit is contained in:
parent
7b4cdaf30c
commit
8437154f48
1 changed files with 12 additions and 0 deletions
12
app/utils.py
12
app/utils.py
|
@ -308,6 +308,18 @@ def allowlist_html(html: str, a_target='_blank') -> str:
|
|||
re_superscript = re.compile(r'\^(\S+)\^')
|
||||
clean_html = re_superscript.sub(r'<sup>\1</sup>', clean_html)
|
||||
|
||||
# replace <img src> for mp4 with <video> - treat them like a GIF (autoplay, but initially muted)
|
||||
re_embedded_mp4 = re.compile(r'<img .*?src="(https://.*?\.mp4)".*?/>')
|
||||
clean_html = re_embedded_mp4.sub(r'<video class="responsive-video" controls preload="auto" autoplay muted loop playsinline disablepictureinpicture><source src="\1" type="video/mp4"></video>', clean_html)
|
||||
|
||||
# replace <img src> for webm with <video> - treat them like a GIF (autoplay, but initially muted)
|
||||
re_embedded_webm = re.compile(r'<img .*?src="(https://.*?\.webm)".*?/>')
|
||||
clean_html = re_embedded_webm.sub(r'<video class="responsive-video" controls preload="auto" autoplay muted loop playsinline disablepictureinpicture><source src="\1" type="video/webm"></video>', clean_html)
|
||||
|
||||
# replace <img src> for mp3 with <audio>
|
||||
re_embedded_mp3 = re.compile(r'<img .*?src="(https://.*?\.mp3)".*?/>')
|
||||
clean_html = re_embedded_mp3.sub(r'<audio controls><source src="\1" type="audio/mp3"></audio>', clean_html)
|
||||
|
||||
return clean_html
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue