Skip to main content

Convert markdown imgs into captioned <figure>s

Project description

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.

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

markdown_img2fig-1.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

markdown_img2fig-1.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file markdown_img2fig-1.0.1.tar.gz.

File metadata

  • Download URL: markdown_img2fig-1.0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for markdown_img2fig-1.0.1.tar.gz
Algorithm Hash digest
SHA256 75cc14d2d978a9d2892239c1b519f94e881bc120cf867ee745e25e26feb586d4
MD5 918bb3dd37679f7afe5100cf07bf8b98
BLAKE2b-256 716014314ed94a6827ca0347aef37fc4503baa8ebf8f496ee69edb66ffcfd15e

See more details on using hashes here.

File details

Details for the file markdown_img2fig-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for markdown_img2fig-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b412965e16739de019782cdc4ec6d36888c198258abe9f33095b9fd297656ef5
MD5 910c3781f20357fec9acba4d4488ae19
BLAKE2b-256 c9a0ae6b9febf395faa353232582fd28f3995743bde430d6d2cffd39cb282677

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page