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
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.1.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for markdown_img2fig-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b412965e16739de019782cdc4ec6d36888c198258abe9f33095b9fd297656ef5 |
|
MD5 | 910c3781f20357fec9acba4d4488ae19 |
|
BLAKE2b-256 | c9a0ae6b9febf395faa353232582fd28f3995743bde430d6d2cffd39cb282677 |