A custom Sphinx extension to easily embed iframes in a Sphinx book
Project description
Iframes
This extension provides an interface to include iframes with relative ease, but does try to provide manners to interact with the various options. This rests purely by setting default CSS values, that the user can overwrite if preferred for individual iframes, but also globally. In general, each iframe is embedded within a div element, which eases sizing.
[!NOTE] Using CSS is complicated and error prone, so always check and never expect that you get what you want.
What does it do?
This extension provides several Sphinx directives:
iframeh5pvideoiframe-figurevideo-figureh5p-figure
that can be used to quickly insert an iframe with standard sizing and styling.
Installation
To use this extension, follow these steps:
Step 1: Install the Package
Install the module sphinx-iframes package using pip:
pip install sphinx-iframes
Step 2: Add to requirements.txt
Make sure that the package is included in your project's requirements.txt to track the dependency:
sphinx-iframes
Step 3: Enable in _config.yml
In your _config.yml file, add the extension to the list of Sphinx extra extensions (important: underscore, not dash this time):
sphinx:
extra_extensions:
.
.
.
- sphinx_iframes
.
.
.
Configuration
The extension provides several configuration values, which can be added to _config.yml:
sphinx:
config:
-
-
-
iframe_blend: true # default value
iframe_saturation: 1.5 # default value
iframe_h5p_autoresize: true # default value
iframe_background: "#ffffff" # default value
iframe_width: calc(100% - 2.8rem) # default value
iframe_aspectratio: auto 2 / 1 # default value
iframe_loading: lazy # default value
-
-
-
iframe_blend:true(default) orfalse:- if
trueall iframes are standard blended with the background and in dark-mode also inverted. - if
falseall non-blended iframes will have background a colored background and no inversion for dark-mode is applied. - there's no need to set the blend or no-blend for individual iframes if it's set in the
_config.yml, unless you want to deviate from the setting set there.
- if
iframe_saturation:1.5(default) or float:- Blended iframes are inverted in dark mode using the CSS filter
invert(1) hue-rotate(180deg) saturation(iframe_saturation).
- Blended iframes are inverted in dark mode using the CSS filter
iframe_h5p_autoresize:true(default) orfalse:- if
trueall h5p iframes are automagically resized to fit the element in which the iframe is loaded. - if
falseno h5p iframes are automagically resized to fit the element in which the iframe is loaded.
- if
iframe_background:"#ffffff"(default) or CSS string:- sets the standard background color of non-blended iframes.
- Any CSS string defining colors can be used, see CSS data type.
- Surround with
" "for hex strings. - Only visible if the content of the iframes has a transparent background.
iframe_width:calc(100% - 2.8rem)(default) or CSS string:- sets the standard width of the iframe within the parent element;
- Any CSS string defining a width can be used, see width CSS property.
iframe_aspectratio:auto 2 / 1(default) or CSS string:- sets the standard aspect ration of the iframe within the parent element;
- Any CSS string defining an aspect ratio can be used, see aspect-ratio CSS property.
iframe_loading:lazy(default) oreager:- sets the standard loading attribute of the iframe;
- see loading attribute.
Provided code
Directives
The following new directives are provided:
```{iframe} <link_to_webpage_to_embed>
```
```{h5p} <link_to_h5p_webpage_to_embed>
```
```{video} <link_to_video_to_embed>
```
In case of a YouTube-link, it is inverted to an embed link if the normal web URL is provided. H5p links are converted too if provided without /embed.
For the video directive, if a direct link to a video file is provided (e.g. ending on .mp4, .webm or .ogg), then the video directive from sphinxcontrib.video is used. If any other link is provided, then an iframe is generated.
```{iframe-figure} <link_to_webpage_to_embed>
:name: some:label
The caption for the iframe.
```
```{h5p-figure} <link_to_h5p_webpage_to_embed>
:name: some:label
The caption for the h5p webpage.
```
```{video-figure} <link_to_video_to_embed>
:name: some:label
The caption for the video.
```
Note that you don't need the full embed code of an iframe. Only the source url should be used.
All of these have the following options:
:class::divclass:- If further CSS styling is needed, then use this option to append a CSS class name to the div surrounding the iframe.
:width:- Sets the width of the iframe. Use CSS compatible strings.
:height:- Sets the width of the iframe. Use CSS compatible strings.
:aspectratio:- Sets the width of the iframe. Use CSS compatible strings.
:styleframe:- Sets the style of the iframe. Use CSS compatible strings. Surround with " ".
:stylediv:- Sets the style of the surrounding div. Use CSS compatible strings. Surround with " ".
:loading:- Sets the loading attribute of the iframe. Use either
lazyoreager. - If unset, the global configuration value is used.
- Sets the loading attribute of the iframe. Use either
For the directive video, if a direct link to a video file is given, then only the options from the video directive from sphinxcontrib.video should be used. For any other link, the options above should be used.
The directives iframe-figure, video-figure and h5p-figure also inherit all options from the figure directive from the extension sphinx_metadata_figure.
Metadata
The iframe-figure, video-figure and h5p-figure directives use the figure directive from the sphinx_metadata_figure extension to add metadata to the figures they create. This metadata can include information such as author, license, copyright, and source. This information is useful for documentation and attribution purposes.
[!NOTE] This extension always loads the extension
sphinx_metadata_figureas it depends on it to add metadata to the figures. This means that also the configuration options of that extension are available and if this is not desired, you must disable the workings of that extensions by applying appropriate settings inmetadata_figure_settingsin your Sphinx configuration file. See the documentation of thesphinx_metadata_figureextension for more information.
Examples and details
See Iframes - TeachBooks Manual.
Contribute
This tool's repository is stored on GitHub. If you'd like to contribute, you can create a fork and open a pull request on the GitHub repository.
The README.md of the branch Manual is also part of the TeachBooks manual as a submodule.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_iframes-1.2.0.tar.gz.
File metadata
- Download URL: sphinx_iframes-1.2.0.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
219b3a06e6b734f1a21413633144255d3dfa1657c2f74ec93e0e9fa090a805ec
|
|
| MD5 |
8a25a52512b2e34cbc3d21f92ac7a657
|
|
| BLAKE2b-256 |
8d6eb1d0c34dffd6352e50f535d5b84b40ebed3d667370335093435977c1a591
|
Provenance
The following attestation bundles were made for sphinx_iframes-1.2.0.tar.gz:
Publisher:
python-publish.yml on TeachBooks/sphinx-iframes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_iframes-1.2.0.tar.gz -
Subject digest:
219b3a06e6b734f1a21413633144255d3dfa1657c2f74ec93e0e9fa090a805ec - Sigstore transparency entry: 742916086
- Sigstore integration time:
-
Permalink:
TeachBooks/sphinx-iframes@e3a6ddddded7054c395ea8187e9959022c16ad52 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/TeachBooks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e3a6ddddded7054c395ea8187e9959022c16ad52 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sphinx_iframes-1.2.0-py3-none-any.whl.
File metadata
- Download URL: sphinx_iframes-1.2.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0275574aaa0977b8a92ca247d7b9fe389d4a0ed6476165eb9975cad703d1d690
|
|
| MD5 |
b4487ca0cc2dcfd66f5885d9fdbfdc0e
|
|
| BLAKE2b-256 |
42082ea6aadc6edeb09784ea94448ecd451b7f79710b4c660dc377e2dd044a3b
|
Provenance
The following attestation bundles were made for sphinx_iframes-1.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on TeachBooks/sphinx-iframes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_iframes-1.2.0-py3-none-any.whl -
Subject digest:
0275574aaa0977b8a92ca247d7b9fe389d4a0ed6476165eb9975cad703d1d690 - Sigstore transparency entry: 742916098
- Sigstore integration time:
-
Permalink:
TeachBooks/sphinx-iframes@e3a6ddddded7054c395ea8187e9959022c16ad52 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/TeachBooks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e3a6ddddded7054c395ea8187e9959022c16ad52 -
Trigger Event:
push
-
Statement type: