Skip to main content

Markdown img2fig

Convert inline markdown images to captioned figures.

Inspirated by markdown-captions and yafg.

Installation

pip install markdown-img2fig

Usage

Markdown module

import markdown
import img2fig

data = markdown.markdown(
    md,
    extensions=[
        img2fig.Img2FigExtension(
            source_attr="title",
            remove_attr=True,
            force_convert=True,
            empty_as_none=True,
        ),
        'attr_list',  # optional
    ]
)

MkDocs mkdocs.yml

markdown_extensions:
  - img2fig:
      source_attr: title
      remove_attr: true
      force_convert: true
      empty_as_none: true
  - attr_list # optional

Result

![Alt text](image.jpg "Title text"){: .someclass }
<figure class="someclass">
    <img alt="Alt text" src="image.jpg" />
    <figcaption>Title text</figcaption>
</figure>

Options

  • source_attr (default: 'title')
    Use 'title' or 'alt' attribute as the caption.
  • remove_attr (default: True)
    Remove the alt/title attribute after conversion.
  • force_convert (default: True)
    Convert all images to figures, missing alt/title will cause figures without figcaptions.
    If false, images will be left as is.
  • empty_as_none (default: True)
    Treat empty alt/title as if they don't exist.

License

Licensed under the MIT License.

Metadata

Release files for markdown-img2fig 1.0.1

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

Source distribution (sdist)

Source distribution for markdown-img2fig 1.0.1
File Size Uploaded
markdown_img2fig-1.0.1.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for markdown-img2fig 1.0.1
File Interpreter ABI Platform
markdown_img2fig-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / markdown_img2fig-1.0.1.tar.gz

Download URL markdown_img2fig-1.0.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
75cc14d2d978a9d2892239c1b519f94e881bc120cf867ee745e25e26feb586d4
BLAKE2b-256 checksum
How to use checksums
716014314ed94a6827ca0347aef37fc4503baa8ebf8f496ee69edb66ffcfd15e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / markdown_img2fig-1.0.1-py3-none-any.whl

Download URL markdown_img2fig-1.0.1-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b412965e16739de019782cdc4ec6d36888c198258abe9f33095b9fd297656ef5
BLAKE2b-256 checksum
How to use checksums
c9a0ae6b9febf395faa353232582fd28f3995743bde430d6d2cffd39cb282677
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

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