Skip to main content

mdit-py-figure

PyPI version Python versions License

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:

![Picture of Oscar.](/path/to/cat.jpg)
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:

![Picture of Oscar.](/path/to/cat1.jpg)
![Picture of Luna.](/path/to/cat2.jpg)
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:

Example of an HTML figure with figcaption.

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 = """
![Picture of Oscar.](/path/to/cat.jpg)
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

Metadata

Release files for mdit-py-figure 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdit-py-figure 1.1.0
File Size Uploaded Provenance Actions
mdit_py_figure-1.1.0.tar.gz 3.1 MB With provenance Details for mdit_py_figure-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mdit-py-figure 1.1.0
File Interpreter ABI Platform Actions
mdit_py_figure-1.1.0-py3-none-any.whl Python 3 none any Details for mdit_py_figure-1.1.0-py3-none-any.whl

Total release size: 3.2 MB

Release files / mdit_py_figure-1.1.0.tar.gz

Download URL mdit_py_figure-1.1.0.tar.gz
Size 3.1 MB
Tags Source
SHA-256 checksum
How to use checksums
8acfd6ca4bfab1814e4bff184915661a5f3f3f00f33e7b85d8acd1fb47768205
BLAKE2b-256 checksum
How to use checksums
1760c357ce77dd642b9e0e9e549dd09ec8c5ef6e1d567a246ff3007bbed422f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 28, 2025.

Transparency log

Release files / mdit_py_figure-1.1.0-py3-none-any.whl

Download URL mdit_py_figure-1.1.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
561511d2042360bf6784af9f06361a454235bfaf39e8204c359de2a92383f85a
BLAKE2b-256 checksum
How to use checksums
e4a825a57270aa2c4f14076563b3f30693354753d526de579ca9c0a2e41d8d05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 28, 2025.

Transparency log

Security for mdit-py-figure 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mdit_py_figure-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 28, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page