markdown-it-py plugin to convert image paragraphs to HTML figure elements
Project description
mdit-py-figure
mdit-py-figure is a
markdown-it-py
plugin to parse markdown paragraphs that start with an image into HTML
<figure> elements. One nice thing is it doesn't use any new markdown
syntaxes.
Example markdown source:

Awesome caption about **Oscar** the kitty.
Render result:
<figure>
<img src="/path/to/cat.jpg" alt="Picture of Oscar." />
<figcaption>Awesome caption about <strong>Oscar</strong> the kitty.</figcaption>
</figure>
Multiple images are supported:


Awesome captions about the **kitties**.
<figure>
<img src="/path/to/cat1.jpg" alt="Picture of Oscar.">
<img src="/path/to/cat2.jpg" alt="Picture of Luna.">
<figcaption>Awesome captions about the <strong>kitties</strong>.</figcaption>
</figure>
Why?
Using dedicated <figure> and <figcaption> elements makes styling images
with descriptions much easier.
Here is an
example:
I hear they are also good for SEO.
Installation
pip install mdit-py-figure
Or with uv:
uv add mdit-py-figure
Usage
from markdown_it import MarkdownIt
from mdit_py_figure import figure_plugin
md = MarkdownIt().use(figure_plugin)
source = """

Awesome caption about **Oscar** the kitty.
"""
html = md.render(source)
print(html)
Option to add link to the image
Example:
md = MarkdownIt().use(figure_plugin, image_link=True)
Render result:
<figure>
<a href="/path/to/cat.jpg">
<img src="/path/to/cat.jpg" alt="Picture of Oscar." />
</a>
<figcaption>Awesome caption about <strong>Oscar</strong> the kitty.</figcaption>
</figure>
See tests/test_figure.py for more examples.
Option to skip images without captions
Example:
md = MarkdownIt().use(figure_plugin, skip_no_caption=True)
In case a link to an image doesn't have a caption (a line of text following it without any linebreaks in between), it won't be wrapped in a <figure>.
See test_skip_no_caption_option() in tests/test_figure.py for an example.
Changelog
See CHANGELOG.md.
LICENSE
Apache-2.0
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 mdit_py_figure-1.1.0.tar.gz.
File metadata
- Download URL: mdit_py_figure-1.1.0.tar.gz
- Upload date:
- Size: 3.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8acfd6ca4bfab1814e4bff184915661a5f3f3f00f33e7b85d8acd1fb47768205
|
|
| MD5 |
dbd57178a7d7b72b42fa44bfafcc6a53
|
|
| BLAKE2b-256 |
1760c357ce77dd642b9e0e9e549dd09ec8c5ef6e1d567a246ff3007bbed422f4
|
Provenance
The following attestation bundles were made for mdit_py_figure-1.1.0.tar.gz:
Publisher:
pypi_upload.yml on mangoumbrella/mdit-py-figure
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdit_py_figure-1.1.0.tar.gz -
Subject digest:
8acfd6ca4bfab1814e4bff184915661a5f3f3f00f33e7b85d8acd1fb47768205 - Sigstore transparency entry: 780671842
- Sigstore integration time:
-
Permalink:
mangoumbrella/mdit-py-figure@5ee9178af25ac5f73cda348adeca47bfa58e56ef -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/mangoumbrella
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_upload.yml@5ee9178af25ac5f73cda348adeca47bfa58e56ef -
Trigger Event:
release
-
Statement type:
File details
Details for the file mdit_py_figure-1.1.0-py3-none-any.whl.
File metadata
- Download URL: mdit_py_figure-1.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 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 |
561511d2042360bf6784af9f06361a454235bfaf39e8204c359de2a92383f85a
|
|
| MD5 |
cda3d6ca53f8000178819140623795d7
|
|
| BLAKE2b-256 |
e4a825a57270aa2c4f14076563b3f30693354753d526de579ca9c0a2e41d8d05
|
Provenance
The following attestation bundles were made for mdit_py_figure-1.1.0-py3-none-any.whl:
Publisher:
pypi_upload.yml on mangoumbrella/mdit-py-figure
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdit_py_figure-1.1.0-py3-none-any.whl -
Subject digest:
561511d2042360bf6784af9f06361a454235bfaf39e8204c359de2a92383f85a - Sigstore transparency entry: 780671845
- Sigstore integration time:
-
Permalink:
mangoumbrella/mdit-py-figure@5ee9178af25ac5f73cda348adeca47bfa58e56ef -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/mangoumbrella
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_upload.yml@5ee9178af25ac5f73cda348adeca47bfa58e56ef -
Trigger Event:
release
-
Statement type: