Skip to content

Commit

Permalink
feat: add a class parameter (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored May 25, 2023
2 parents ac205a0 + aa5ff06 commit 1ee4d30
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ div.highlight-console pre span.go::before {
margin-right: 10px;
margin-left: 5px;
}

/* use to demo the class attribute */
.video-bordered {
border: 0.2em solid red;
}
11 changes: 11 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ the video directive supports all the optional attributes from the html tag as su
``: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
``:class:``,``str``, Set extra class to the video html tag

They can be used as any directive option:

Expand All @@ -72,6 +73,16 @@ They can be used as any directive option:
:muted:
:loop:

And using the ``:class:`` parameter in combination with custom css, you can change the display of the html ``<video>`` tag:

.. code-block:: rst
.. video:: _static/video.mp4
:class: video-bordered
.. video:: _static/video.mp4
:class: video-bordered

Advanced Usage
--------------

Expand Down
4 changes: 4 additions & 0 deletions sphinxcontrib/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Video(SphinxDirective):
"poster": directives.unchanged,
"preload": directives.unchanged,
"width": directives.unchanged,
"class": directives.unchanged,
}

def run(self) -> List[video_node]:
Expand Down Expand Up @@ -142,6 +143,7 @@ def run(self) -> List[video_node]:
poster=self.options.get("poster", ""),
preload=preload,
width=width,
klass=self.options.get("class", ""),
)
]

Expand All @@ -150,6 +152,8 @@ def visit_video_node_html(translator: SphinxTranslator, node: video_node) -> Non
"""Entry point of the html video node."""
# start the video block
attr: List[str] = [f'{k}="{node[k]}"' for k in SUPPORTED_OPTIONS if node[k]]
if node["klass"]: # klass need to be special cased
attr += [f"class=\"{node['klass']}\""]
html: str = f"<video {' '.join(attr)}>"

# build the sources
Expand Down

0 comments on commit 1ee4d30

Please sign in to comment.