Skip to main content

vexy-python-markdown-figure-groups

Place a figure beside the paragraphs it illustrates. The package wraps the figure and its text in one HTML block and gives your stylesheet a paragraph count.

Install

Requires Python 3.12 or later. Install the vexy-python-markdown-figure-groups distribution and import it as vexy_markdown_figure_groups.

pip install vexy-python-markdown-figure-groups
# Or, in a uv project
uv add vexy-python-markdown-figure-groups

Before and after

Put the figure immediately after the paragraph it illustrates. Use a double-quoted class attribute on the figure.

<p>The crossbar sits below the centre of the A.</p>
<figure class="img-small"><img src="a.svg" alt="A with a low crossbar"></figure>
<p>This leaves room for the counter above.</p>

The two paragraphs give the figure two grid rows to span.

<div class="figure-group" style="--rows: 2"><p>The crossbar sits below the centre of the A.</p>
<figure class="img-small"><img src="a.svg" alt="A with a low crossbar"></figure>
<p>This leaves room for the counter above.</p></div>

Consecutive paragraphs join the group until another block intervenes or a paragraph has a figure of its own. A figure immediately after a heading groups with the paragraphs that follow it. A cut figure moves ahead of its paragraph so text can wrap around a float.

Grouping applies to top-level article content. It skips lists, divs, details, blockquotes, tables and nested figures. It preserves comments and the contents of script, style, pre and textarea. Running it twice keeps a single wrapper.

Use with Python-Markdown

Enable the vexy_figure_groups extension to group figures in Markdown's final HTML, after the renderer restores raw HTML blocks.

import markdown

text = """The crossbar sits below the centre of the A.

<figure class="img-small"><img src="a.svg" alt="A with a low crossbar"></figure>

This leaves room for the counter above."""
html = markdown.markdown(text, extensions=["md_in_html", "attr_list", "vexy_figure_groups"])

Pass options through extension_configs, for example extension_configs={"vexy_figure_groups": {"group_class": "margin-note"}}.

Use with rendered HTML

If a site creates figures after Markdown rendering, call the public group_figures() function from your own plugin after the figures exist. For example, a MkDocs plugin that creates figures in on_page_content can return group_figures(html) at the end of that hook.

from vexy_markdown_figure_groups import group_figures

html = '<p>Check the crossbar.</p><figure class="img-cut"><img src="a.svg" alt="A"></figure>'
grouped = group_figures(html, group_class="fly-aside", cut_class="fly-cut")

Options

The extension and the function accept the same options. Pass the function's options by keyword. Use lists or tuples for class collections and literal CSS identifiers for class names. Invalid names raise ValueError.

Option Default Meaning
figure_classes ("img-small", "img-tall", "img-cut") Figure classes eligible for grouping.
cut_classes ("img-cut",) Classes that move an eligible figure ahead of its paragraph.
group_class "figure-group" Class added to every wrapper.
cut_class "figure-group-cut" Additional wrapper class for cut figures.
rows_property "--rows" CSS custom property holding the paragraph count. Its name starts with --.

Layout

On wide screens, give the figure a margin column spanning the paragraph rows. Cut figures can float into the text instead.

@media (min-width: 48rem) {
  .figure-group {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 16rem); column-gap: 2rem;
  }
  .figure-group > p { grid-column: 1; }
  .figure-group > figure { grid-column: 2; grid-row: 1 / span var(--rows); margin: 0; }
  .figure-group img { max-width: 100%; height: auto; }
  .figure-group-cut { display: flow-root; }
  .figure-group-cut > figure { float: right; width: 35%; margin: 0 0 1rem 1.5rem; }
}

Releasing

For the first release, build from a clean checkout at the local v0.1.0 tag with uv build, then run uv publish on that machine using a PyPI API token. In the project's PyPI publishing settings, register a GitHub trusted publisher for vexyart/vexy-python-markdown-figure-groups, workflow release.yml, environment pypi. Push a new v* tag for each subsequent release.

Licensed under Apache-2.0.

Metadata

Release files for vexy-python-markdown-figure-groups 0.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 vexy-python-markdown-figure-groups 0.1.0
File Size Uploaded Provenance Actions
vexy_python_markdown_figure_groups-0.1.0.tar.gz 15.2 kB Without provenance Details for vexy_python_markdown_figure_groups-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vexy-python-markdown-figure-groups 0.1.0
File Interpreter ABI Platform Actions
vexy_python_markdown_figure_groups-0.1.0-py3-none-any.whl Python 3 none any Details for vexy_python_markdown_figure_groups-0.1.0-py3-none-any.whl

Total release size: 26.8 kB

Release files / vexy_python_markdown_figure_groups-0.1.0.tar.gz

Download URL vexy_python_markdown_figure_groups-0.1.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7b7c506d9e792e387e57fffd0f55be918b93a5e0dc9a536967d5ce8f06d75b11
BLAKE2b-256 checksum
How to use checksums
1260b2d7a64fe0859970ecca8f1b2ccfbecf5db73f343622b2220595f457bba3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / vexy_python_markdown_figure_groups-0.1.0-py3-none-any.whl

Download URL vexy_python_markdown_figure_groups-0.1.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9224022a735492d1aa25c669f12c44733ecd76c8c76921c90c45b81f0d628b8a
BLAKE2b-256 checksum
How to use checksums
d89b5a41e6a7efb428e7e945086eae47e081b551880d0d24b7b69114c9f343b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for vexy-python-markdown-figure-groups 0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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