Skip to main content

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 for 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 if actual style is needed.

/* _static/css/custom.css */

/* example */
.inline-svg {
  max-width: 100%;
  height: auto;
}

And add it in conf.py as follows.

# conf.py

def setup(app):
    app.add_css_file('css/custom.css')

[!NOTE] Even if you don't define actual style, giving the class will inline SVGs.

Hyperlink

To make text in SVG a hyperlink, for example, edit it as follows in draw.io.

drawio_edit_link.png

drawio_link_dialog.png

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.

Known problems

It has been reported that inlining SVG images saved by Draw.io Integration extension of VSCode with sphinx-inline-svg results in garbled characters. 😥

In addition, hyperlinks in SVG images saved by Draw.io Integration may not become clickable. In such cases, inlining with sphinx-inline-svg does not make them clickable. 😥

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_inline_svg-0.1.2.tar.gz (76.4 kB view details)

Uploaded Source

Built Distribution

sphinx_inline_svg-0.1.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_inline_svg-0.1.2.tar.gz.

File metadata

  • Download URL: sphinx_inline_svg-0.1.2.tar.gz
  • Upload date:
  • Size: 76.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for sphinx_inline_svg-0.1.2.tar.gz
Algorithm Hash digest
SHA256 138d2d8fc1ab963b7a3a35547f321254fd6355d3f24748148fc31d5658d10294
MD5 1c5c992b8a30d60a41d5e8c985cd70f3
BLAKE2b-256 96de0d4f7596bb958c67fa9b4c4982239e28f81cc97724fe5ed4fb39905ecfe0

See more details on using hashes here.

File details

Details for the file sphinx_inline_svg-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_inline_svg-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 12672d534b9d5788b8725ee000efaf7b93f130cb0228a5d4e4393ffb38315239
MD5 990cb623464facdd333b69e5cc25fd3b
BLAKE2b-256 32aacc44aa9e633e04cea2fb2359ff8faff821b1d58f87f53e7783164d730d9f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page