Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
feat: add loop, muted, controls attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
soulless-viewer committed Feb 6, 2023
1 parent b680e31 commit 3aaa842
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions mkdocs_video/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Plugin(mkdocs.plugins.BasePlugin):
("mark", config_options.Type(str, default="type:video")),
("is_video", config_options.Type(bool, default=False)),
("video_type", config_options.Type(str, default="mp4")),
("video_muted", config_options.Type(bool, default=False)),
("video_loop", config_options.Type(bool, default=False)),
("video_controls", config_options.Type(bool, default=True)),
("video_autoplay", config_options.Type(bool, default=False)),
("css_style", config_options.Type(dict, default={
"position": "relative",
Expand Down Expand Up @@ -64,23 +67,31 @@ def create_repl_tag(self, src):
)

is_video = self.config["is_video"]
autoplay = self.config["video_autoplay"]
video_loop = self.config["video_loop"]
video_muted = self.config["video_muted"]
video_controls = self.config["video_controls"]
video_autoplay = self.config["video_autoplay"]
video_type = self.config['video_type'].lower().strip()
if " " in video_type or "/" in video_type:
raise ConfigurationError("Unsupported video type")
video_type = f"video/{video_type}"

tag = (
f"<video style=\"{style}\" controls {'autoplay' if autoplay else ''} >"
f"<source src=\"{src}\" type=\"{video_type}\" />"
"</video>"
f'<video style="{style}"'
f'{" loop" if video_loop else ""}'
f'{" muted" if video_muted else ""}'
f'{" controls" if video_controls else ""}'
f'{" autoplay" if video_autoplay else ""}'
'>'
f'<source src="{src}" type="{video_type}" />'
'</video>'
) if is_video else (
f"<iframe src=\"{src}\" style=\"{style}\" "
"frameborder=\"0\" allowfullscreen>"
"</iframe>"
f'<iframe src="{src}" style="{style}" frameborder="0"'
'allowfullscreen>'
'</iframe>'
)

return f"<div class=\"video-container\">{tag}</div>"
return f'<div class="video-container">{tag}</div>'


def find_marked_tags(self, content):
Expand Down

0 comments on commit 3aaa842

Please sign in to comment.