Skip to content

Commit

Permalink
Support for relative width (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Nov 11, 2024
2 parents 6fe9ebb + fc8a2a8 commit a817d1c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 4 additions & 2 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ the video directive supports all the optional attributes from the html tag as su
``:alt:``,``str``,Specify the text to write when the video cannot be displayed
``:autoplay:``,,Specifies that the video will start playing as soon as it is ready
``:nocontrols:``,,Specifies that video controls should not be displayed (such as a play/pause button etc).
``:height:``,``int``,Sets the height of the video player in pixels
``:height:``,``int``,Sets the height of the video player in pixels (ignored if relative width is used)
``:loop:``,,Specifies that the video will start over again, every time it is finished
``:muted:``,,Specifies that the audio output of the video should be muted
``:poster:``,``str``, Specifies an image url to be shown while the video is downloading, or until the user hits the play button
``:preload:``,``str``,"Specifies if and how the author thinks the video should be loaded when the page loads. Can only be values from ``['auto', 'metadata', 'none']``"
``:width:``,``int``, Sets the width of the video player in pixels
``:width:``,``int``\ [``%``\ ], Sets the width of the video player in pixels or relative to the page's width if a percentage
``:class:``,``str``, Set extra class to the video html tag
``:playsinline:``,,Specifies that the video will play in-line (instead of full-screen) on small devices.

Expand All @@ -70,13 +70,15 @@ They can be used as any directive option:
:muted:
:loop:
:poster: _static/image.png
:width: 100%
.. video:: _static/video.mp4
:nocontrols:
:autoplay:
:playsinline:
:muted:
:loop:
:width: 100%
:poster: _static/image.png

And using the ``:class:`` parameter in combination with custom css, you can change the display of the html ``<video>`` tag:
Expand Down
26 changes: 18 additions & 8 deletions sphinxcontrib/video/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,30 @@ def run(self) -> List[video_node]:
env: BuildEnvironment = self.env

# check options that need to be specific values
height: str = self.options.get("height", "")
if height and not height.isdigit():
logger.warning(
f'The provided height ("{height}") is ignored as it\'s not an integer'
)
height = ""

width: str = self.options.get("width", "")
if width and not width.isdigit():
if width and not (width.isdigit() or width[-1] == "%" and width[:-1].isdigit()):
logger.warning(
f'The provided width ("{width}") is ignored as it\'s not an integer'
f'The provided width ("{width}") is ignored as it\'s not an integer '
"or integer percentage"
)
width = ""

height: str = self.options.get("height", "")
if height:
if width.endswith("%"):
logger.warning(
f'The provided height ("{height}") is ignored as the provided '
f'width ("{width}") is relative'
)
height = ""
elif not height.isdigit():
logger.warning(
f'The provided height ("{height}") is ignored as it\'s not an '
"integer"
)
height = ""

preload: str = self.options.get("preload", "auto")
valid_preload = ["auto", "metadata", "none"]
if preload not in valid_preload:
Expand Down

0 comments on commit a817d1c

Please sign in to comment.