A Sphinx extension to convert ASCII diagrams to SVGs with Svgbob.
Project description
sphinxcontrib-svgbob
A Sphinx extension to render ASCII diagrams into SVG using Svgbob.
🗺️ Overview
Diagrams to be included into Sphinx documentation are commonly described with a dedicated markup language, and converted into an image by Sphinx when the documentation is built. However, this reduces the legibility of the documentation source for readers that are not browsing the HTML version.
Svgbob is a diagramming model implemented in Rust that can convert ASCII diagrams into SVG. Using it allows you to:
- Keep a textual version of the diagram in your documentation, so that it remains legible.
- Render a nicer version as SVG for HTML or PDF versions of the documentation.
This Sphinx extension builds Svgbob statically and lets you use it to render ASCII diagrams within Sphinx documentation. Since it does not require any external dependency, it's also suitable to use on readthedocs.org.
🔧 Installing
sphinxcontrib-svgbob
can be installed from PyPI,
which hosts some pre-built CPython wheels for x86-64 Linux and OSX, as well as the code required
to compile from source:
$ pip install sphinxcontrib-svgbob
If a Rust compiler is not available, the setup.py
script will attempt to
install a temporary copy if the package is compiled on a UNIX system. If
it doesn't work, see the
documentation on rust-lang.org
to learn how to install Rust on your machine.
💡 Example
Use the svgbob
directive in a function docstring to show a diagram of what
is being computed:
def hamming(x, y):
"""Compute the Hamming distance between two strings.
Hamming distance between two strings of equal length is the number of
positions at which the corresponding symbols are different. For instance,
Hamming distance for a 3-bit string can be computed visually using a
3-bit binary cube:
.. svgbob::
:align: center
110 111
*-----------*
/| /|
/ | 011 / |
010 *--+--------* |
| | 100 | |
| *--------+--* 101
| / | /
|/ |/
000 *-----------* 001
The minimum distance between any two vertices is the Hamming distance
between the two bit vectors (e.g. 100→011 has distance 3).
"""
When Sphinx (and autodoc
) renders the docstring of this function, you'll get
the following HTML page (here shown with the Sphinx theme for readthedocs.org):
And yet, the help(hamming)
will still look nice and helpful:
🔩 Configuration
The svgbob
directive supports the following arguments:
font-size
(integer): the size of the text to be rendered, defaults to 14.font-family
: the family of the font used to render the text, defaults to monospace.fill-color
(CSS color): the color to use to fill closed shapes.stroke-color
(CSS color): the color to use to paint strokes, defaults to black.scale
(float): the SVG scale of the figure, defaults to 8.0.align
(CSS align value): the alignment of the resulting image.class
(HTML class): an arbitrary class to add to the resulting HTML element.
For instance, use the following to use Arial with size 12, to render nicer text in the diagram blocks:
.. svgbob::
:font-family: Arial
:font-size: 12
+-------+ +--------+
| Hello |------>| World! |
+-------+ +--------+
💭 Feedback
⚠️ Issue Tracker
Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker if you need to report or ask something. If you are filing in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.
🏗️ Contributing
Contributions are more than welcome! See CONTRIBUTING.md
for more details.
📚 Alternatives
sphinxcontrib-kroki
also lets you use Svgbob to convert ASCII diagrams, but it queries the kroki.io website to do so, and does not support the new options from Svgbob v0.5.sphinxcontrib-aafig
uses theaafigure
binary to convert ASCII diagrams.
🔨 Credits
sphinxcontrib-svgbob
is developped and maintainted by:
The structure of this repository was adapted from the aforementioned
sphinxcontrib-kroki
repository, as I had no experience setting up a
Sphinx extension otherwise.
⚖️ License
This library is provided under the MIT License.
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
Built Distributions
Hashes for sphinxcontrib.svgbob-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04a6f8c5aa10cf431812d06d2d3ddab8fef22fee89a62a7ddf93e33120fd7648 |
|
MD5 | cab2e9a1d822ae5090f4cbaa2438259e |
|
BLAKE2b-256 | c9dc42dfabdce2d59a6a3e0250886d2c364f7176587e5e5857e5e0a4e07e6127 |
Hashes for sphinxcontrib.svgbob-0.1.0-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b27408f189e68dd4ce0ba38d5ee4663cd93aa9bdad08b63b4c5a5f6f540334db |
|
MD5 | 75a71e2556fb4690894d92fcff2b6cf6 |
|
BLAKE2b-256 | 4a60c4053ba9a99c4a8a12f90fc9ce7468c14b89595476e11fec2459e5b8df0c |
Hashes for sphinxcontrib.svgbob-0.1.0-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0b6f17675745eb5d32586469656de9ac2bada0f47fc24e2e2e416e9b3b73b05 |
|
MD5 | 6f8f2373511429ce5db38a2f4911e5c3 |
|
BLAKE2b-256 | c49b119a5fe896402295bdadcb111babdbc1abff645b74665f3b0fc573a68764 |
Hashes for sphinxcontrib.svgbob-0.1.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07649f4952912caad52fc2123db8a215a6d199d146c1fe9898c27164922aa1b3 |
|
MD5 | 426d0668633d0cb584f339f354d0efaa |
|
BLAKE2b-256 | d4f0a5a2aaa733a1923f54cb9ca7fb86db9647d1c797af0428521040e5b45cc6 |
Hashes for sphinxcontrib.svgbob-0.1.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 227d2f6704726ded9b8144c96afa8373fd7a0b29f2ddd0821308d218f7c25a85 |
|
MD5 | ec30fe5a2346c60d719ab2a1228c7889 |
|
BLAKE2b-256 | 2749f3f8380d137bf1560160e02b38dd847222b369e282d6e976b2ecd1bcae18 |
Hashes for sphinxcontrib.svgbob-0.1.0-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca15f2497700214f7b09b94a250a56fd1e66ca3419802189dfb7e04e85dcf3bb |
|
MD5 | 8e0cd0f8af077bc53fbf635b39b66479 |
|
BLAKE2b-256 | 4c4305504ab97e4e04041c11fe3dd1f1d6d71bab034a08966b784ad70ab4706e |
Hashes for sphinxcontrib.svgbob-0.1.0-pp36-pypy36_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bf6796a4908bd1f205b867f767c8761faf215cd6780203a1beb9e21e99671e1 |
|
MD5 | 05ea0d5e0f3e5900be02dd4a923a1bf0 |
|
BLAKE2b-256 | bf7aacce89b7e007624d516fe1d2e873765bf3b99b62af85f19491313f8a07b6 |
Hashes for sphinxcontrib.svgbob-0.1.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 501038bc6c76283796d0bef66aabeccd516916f2e098b1930b1c2a308e97a36f |
|
MD5 | 353af3119ce6af4ba34eac9136b3baa7 |
|
BLAKE2b-256 | 8a6099a3329b16e1c984e9de80205d31be2f776b4fe4601b3d442ba458d464ed |
Hashes for sphinxcontrib.svgbob-0.1.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8c913f0e26c021953be767be78a0b912363e404d83b230809f382aa69005a57 |
|
MD5 | 4a8218d78636c8f53a76a0ec9e5c77db |
|
BLAKE2b-256 | 03760fd582fa5a150fff1546d14355411019bbbdc1728f167aa802b555f19fbb |
Hashes for sphinxcontrib.svgbob-0.1.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fd36ac955f0d5ca805c4f05e31f9abe4072fd37a499417bbb3120dd660580f3 |
|
MD5 | fd9417ca77d573bbca236b6d3c44106c |
|
BLAKE2b-256 | 2b658b0e60648fd2f02c9240571e92276264b9cc61ff4806b077020f8d11179c |
Hashes for sphinxcontrib.svgbob-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41ffd7c1c38fb848485f7c7c468688f4662363191bcf754c291abe6b35882677 |
|
MD5 | efd3cad36c3beaad93cc553bc06b245d |
|
BLAKE2b-256 | 4d25e74f297f089111ee9877a67a8c1ef5e0bfd3918ac2a2b2dd6ad3e9298dd7 |
Hashes for sphinxcontrib.svgbob-0.1.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a675f76bab10049a0f0f59ef48564c6a3387e11637665d9abb088070de62d161 |
|
MD5 | 9f5681763a9e545ed837e4369a4a1067 |
|
BLAKE2b-256 | fc409be806d72eb09ee2dcba15076568526bce381c0c1ee7850cb77d25b788eb |
Hashes for sphinxcontrib.svgbob-0.1.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b05fce3b9f6061c76cb2a1f06833418b148e5d8a3458abfb2a6049b5b47baa0 |
|
MD5 | 29ae147b5ba553f6bba1ed91723c9bc0 |
|
BLAKE2b-256 | b3ec08d6939ad6e2132951579cb96ca1528c76ea65e9435aadccb8729c1ec1ab |
Hashes for sphinxcontrib.svgbob-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed1b6d354d094ab58ecc560d2dadb44586bc49e16d9d649d9521784c4ac1041c |
|
MD5 | e311f793fd8f6441581b54e2890018c0 |
|
BLAKE2b-256 | 46334bd2f8a4fc3b5297d030258ced2d84c6df28fcf99fc1f43e206bac86359d |
Hashes for sphinxcontrib.svgbob-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69386e9388735dc27caa5b407bdcbbb03a074904d127668b32eb603f880aee4c |
|
MD5 | 492e5946882d77781c0088f7faa09198 |
|
BLAKE2b-256 | 371f64ed78a2f0d16a60af19a57f6d3a8b696e3934e37d2d8f6b890b23a6803b |
Hashes for sphinxcontrib.svgbob-0.1.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0efff5ff58c696e6dae0548266867bdef20e0155bd11896bea83acf0304f5a6 |
|
MD5 | 93f2d23f4626301c0ca417efcdcd3abd |
|
BLAKE2b-256 | d5fc896e5067adb2a5ea5992646366112c6d23f89003c3d15941baea13e0fac8 |
Hashes for sphinxcontrib.svgbob-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ffa3aeb3dfcb0bc23f4b92198663c0e43391cca1a005b570e8ceb3474e5bb50 |
|
MD5 | ad01f4d978d9813ca2cc82b3cc01873b |
|
BLAKE2b-256 | 644617fa2fe70c65f1d726c2480f9f67bf5a423414a5ccd18c1069f282179198 |
Hashes for sphinxcontrib.svgbob-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c91b8fd931ce61215b7e31cdbad9fe6f36208527e12ca9b4477280d617563a1 |
|
MD5 | ab03fdc202566d98d0a061599237e271 |
|
BLAKE2b-256 | 25a014959777d88ef0007e440068d18017eee561a24c0007bfc391662a27c959 |
Hashes for sphinxcontrib.svgbob-0.1.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71f70ba63a9103fd1500bf2c1bed5488228c9863c53681306ac3e243cb2a1d34 |
|
MD5 | db2e47d3ba9b2b4da0ad5d22d4e02f20 |
|
BLAKE2b-256 | f4b025416c96d7c4813aa09739c80a89d679be87128cb1f9483d08515601d9da |