Updated video player.
This commit is contained in:
		
							parent
							
								
									7c4334fe7b
								
							
						
					
					
						commit
						c463dc6dca
					
				| @ -23,7 +23,35 @@ def set_link_target_blank(text): | |||||||
|             element.replace_with(BeautifulSoup(embed_template, 'html.parser')) |             element.replace_with(BeautifulSoup(embed_template, 'html.parser')) | ||||||
| 
 | 
 | ||||||
|     return str(soup) |     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): | def linkify_https(text): | ||||||
|     if not "https://" in text: |     if not "https://" in text: | ||||||
| @ -83,7 +111,11 @@ class LinkifyExtension(Extension): | |||||||
|         ).set_lineno(line_number) |         ).set_lineno(line_number) | ||||||
| 
 | 
 | ||||||
|     def _to_html(self, md_file, caller): |     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): | class PythonExtension(Extension): | ||||||
|     tags = {"py3"} |     tags = {"py3"} | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user