Sphinx extension to make svg images inline
Project description
sphinx-inline-svg
Overview
Sphinx extension to make SVG images inline.
It helps to make text in SVG into hyperlink.
If the builder is not html
, it has no effect.
Installation
pip
pip install sphinx-inline-svg
rye
rye add --dev sphinx-inline-svg
Usage
conf.py
Add it to extensions
.
# conf.py
extensions = [
'sphinx_inline_svg',
]
Add CSS class
Add CSS class to SVG image to be inlined.
.. image:: img/chart.drawio.svg
:class: inline-svg
As of MyST, enable attrs_inline
in conf.py.
# conf.py
myst_enable_extensions = [
"attrs_inline",
]
![](img/chart.drawio.svg){.inline-svg}
Define inline-svg
class in CSS.
/* _static/css/custom.css */
/* example */
.inline-svg {
max-width: 100%;
height: auto;
}
Add it in conf.py as follows if defined in _static/css.
# conf.py
def setup(app):
app.add_css_file('css/custom.css')
Hyperlink
To make text in SVG a hyperlink, for example, edit it as follows in draw.io.
Link notation
Link destination that is generated after build depends on Link notation.
Notation | Generated destination | Example | Destination for example |
---|---|---|---|
Starts with "/". | Path from project root. | /index.rst | Top page. |
Starts with "#". | Defined cross-reference target. | #target-1 | Position defined as "#target-1" in the project. |
Starts with "http://" and so on. | As is. | https://google.com | The site on the Internet. |
Other than above. | Relative path from the page. | detail.rst | detail.html file in the same directory. |
[!NOTE] As for the last notation, generated destination is relative from the page where SVG is extracted to, not from the SVG itself.
Configuration
The following settings can be configured in conf.py. If you do not write the configuration itself, the default value is applied.
# conf.py
inline_svg_classes = ['inline-svg', 'selectable-svg']
Name | Type | Description | Default value |
---|---|---|---|
inline_svg_classes | list[str] |
List of class names. SVG image with any of these will be inlined. | ['inline-svg'] |
inline_svg_del_attrs | list[str] |
List of attribute names to be deleted from svg element when extracted. | ['content'] |
inline_svg_resolve_xref | bool |
Whether to convert destination as described in the above "Link notation" section. | True |
[!NOTE] The svg element in SVG file saved by draw.io has "content" attribute, but this is data for editing by the draw.io app, so it is not necessary for the svg element to be inlined.
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
File details
Details for the file sphinx_inline_svg-0.1.1.tar.gz
.
File metadata
- Download URL: sphinx_inline_svg-0.1.1.tar.gz
- Upload date:
- Size: 96.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e8729631866e82bf0d1c79792366c19da6edddde8e95ae505bc4f95a800fcb9 |
|
MD5 | 8cf53971c8f4c2134bd8fbd1aaf753d4 |
|
BLAKE2b-256 | 74c91363828186c5ff1259e52f765c4620dde07c1587492cf6446f3f6338f90b |
File details
Details for the file sphinx_inline_svg-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: sphinx_inline_svg-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 536bb7c9e9059bad6ebe9105a12f27b36b3c67ecc69d2a0fdf3d60e1faadb7b9 |
|
MD5 | a28b529ab908795666152394486f526b |
|
BLAKE2b-256 | 96ffd79b3e0b879d56ebf19d49439eb545403a372e9c99a428317e59cfd9d989 |