Updated video player.
This commit is contained in:
parent
7c4334fe7b
commit
c463dc6dca
@ -24,6 +24,34 @@ def set_link_target_blank(text):
|
||||
|
||||
return str(soup)
|
||||
|
||||
def embed_youtube(text):
|
||||
soup = BeautifulSoup(text, 'html.parser')
|
||||
for element in soup.find_all("a"):
|
||||
if element.attrs['href'].startswith("https://www.you") and "?v=" in element.attrs["href"]:
|
||||
video_name = element.attrs["href"].split("?v=")[1].split("&")[0]
|
||||
embed_template = f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_name}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>'
|
||||
element.replace_with(BeautifulSoup(embed_template, 'html.parser'))
|
||||
return str(soup)
|
||||
|
||||
def embed_image(text):
|
||||
soup = BeautifulSoup(text, 'html.parser')
|
||||
for element in soup.find_all("a"):
|
||||
for extension in [".png", ".jpeg", ".gif", ".webp", ".svg", ".bmp", ".tiff", ".ico", ".heif"]:
|
||||
if extension in element.attrs['href'].lower():
|
||||
embed_template = f'<img src="{element.attrs["href"]}" title="{element.attrs["href"]}" alt="{element.attrs["href"]}" />'
|
||||
element.replace_with(BeautifulSoup(embed_template, 'html.parser'))
|
||||
return str(soup)
|
||||
|
||||
def embed_media(text):
|
||||
soup = BeautifulSoup(text, 'html.parser')
|
||||
for element in soup.find_all("a"):
|
||||
for extension in [".mp4", ".mp3", ".wav", ".ogg", ".webm", ".flac", ".aac",".mpg",".avi",".wmv"]:
|
||||
if extension in element.attrs['href'].lower():
|
||||
embed_template = f'<video controls> <source src="{element.attrs["href"]}">Your browser does not support the video tag.</video>'
|
||||
element.replace_with(BeautifulSoup(embed_template, 'html.parser'))
|
||||
return str(soup)
|
||||
|
||||
|
||||
|
||||
def linkify_https(text):
|
||||
if not "https://" in text:
|
||||
@ -83,7 +111,11 @@ class LinkifyExtension(Extension):
|
||||
).set_lineno(line_number)
|
||||
|
||||
def _to_html(self, md_file, caller):
|
||||
return linkify_https(caller())
|
||||
result = linkify_https(caller())
|
||||
result = embed_media(result)
|
||||
result = embed_image(result)
|
||||
result = embed_youtube(result)
|
||||
return result
|
||||
|
||||
class PythonExtension(Extension):
|
||||
tags = {"py3"}
|
||||
|
Loading…
Reference in New Issue
Block a user