Convert markdown imgs into captioned <figure>s
Project description
Markdown img2fig
Convert inline markdown images to captioned figures.
Inspirated by markdown-img2fig 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
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
markdown_img2fig-1.0.0.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for markdown_img2fig-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d0e682e557e05f133fd5863784fa25ffb5ed6442bd296b106b5c4486f1c265a |
|
MD5 | b1e60355052a9c5ab6a3ffb3c2677a79 |
|
BLAKE2b-256 | 6d5d0db30f60f6dc0448ae505a026f2fafbbef19d79b26a85e76132563c80b8b |