Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a class parameter #28

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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