# Markdown img2fig
Convert inline markdown images to captioned figures.
Inspirated by [markdown-captions](https://github.com/Evidlo/markdown_captions) and [yafg](https://git.sr.ht/~ferruck/yafg).
## Installation
``` bash
pip install markdown-img2fig
```
## Usage
### Markdown module
``` python
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`
``` yaml
markdown_extensions:
- img2fig:
source_attr: title
remove_attr: true
force_convert: true
empty_as_none: true
- attr_list # optional
```
### Result
``` md
![Alt text](image.jpg "Title text"){: .someclass }
```
``` html
<figure class="someclass">
<img alt="Alt text" src="image.jpg" />
<figcaption>Title text</figcaption>
</figure>
```
## Options
- `source_attr` (default: 'title')<br>
Use 'title' or 'alt' attribute as the caption.
- `remove_attr` (default: True)<br>
Remove the alt/title attribute after conversion.
- `force_convert` (default: True)<br>
Convert all images to figures, missing alt/title will cause figures without figcaptions.<br>
If false, images will be left as is.
- `empty_as_none` (default: True)<br>
Treat empty alt/title as if they don't exist.
## License
Licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": "https://github.com/zetaloop/markdown_img2fig",
"name": "markdown-img2fig",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "markdown img figure caption",
"author": "zetaloop",
"author_email": "zetaloop@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/71/60/14314ed94a6827ca0347aef37fc4503baa8ebf8f496ee69edb66ffcfd15e/markdown_img2fig-1.0.1.tar.gz",
"platform": null,
"description": "# Markdown img2fig\r\n\r\nConvert inline markdown images to captioned figures.\r\n\r\nInspirated by [markdown-captions](https://github.com/Evidlo/markdown_captions) and [yafg](https://git.sr.ht/~ferruck/yafg).\r\n\r\n## Installation\r\n\r\n``` bash\r\npip install markdown-img2fig\r\n```\r\n\r\n## Usage\r\n\r\n### Markdown module\r\n``` python\r\nimport markdown\r\nimport img2fig\r\n\r\ndata = markdown.markdown(\r\n md,\r\n extensions=[\r\n img2fig.Img2FigExtension(\r\n source_attr=\"title\",\r\n remove_attr=True,\r\n force_convert=True,\r\n empty_as_none=True,\r\n ),\r\n 'attr_list', # optional\r\n ]\r\n)\r\n```\r\n\r\n### MkDocs `mkdocs.yml`\r\n``` yaml\r\nmarkdown_extensions:\r\n - img2fig:\r\n source_attr: title\r\n remove_attr: true\r\n force_convert: true\r\n empty_as_none: true\r\n - attr_list # optional\r\n```\r\n\r\n### Result\r\n``` md\r\n![Alt text](image.jpg \"Title text\"){: .someclass }\r\n```\r\n``` html\r\n<figure class=\"someclass\">\r\n <img alt=\"Alt text\" src=\"image.jpg\" />\r\n <figcaption>Title text</figcaption>\r\n</figure>\r\n```\r\n\r\n\r\n## Options\r\n\r\n- `source_attr` (default: 'title')<br>\r\n Use 'title' or 'alt' attribute as the caption.\r\n- `remove_attr` (default: True)<br>\r\n Remove the alt/title attribute after conversion.\r\n- `force_convert` (default: True)<br>\r\n Convert all images to figures, missing alt/title will cause figures without figcaptions.<br>\r\n If false, images will be left as is.\r\n- `empty_as_none` (default: True)<br>\r\n Treat empty alt/title as if they don't exist.\r\n\r\n## License\r\n\r\nLicensed under the MIT License.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Convert markdown imgs into captioned <figure>s",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/zetaloop/markdown_img2fig"
},
"split_keywords": [
"markdown",
"img",
"figure",
"caption"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c9a0ae6b9febf395faa353232582fd28f3995743bde430d6d2cffd39cb282677",
"md5": "910c3781f20357fec9acba4d4488ae19",
"sha256": "b412965e16739de019782cdc4ec6d36888c198258abe9f33095b9fd297656ef5"
},
"downloads": -1,
"filename": "markdown_img2fig-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "910c3781f20357fec9acba4d4488ae19",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 4491,
"upload_time": "2024-09-10T06:12:16",
"upload_time_iso_8601": "2024-09-10T06:12:16.321064Z",
"url": "https://files.pythonhosted.org/packages/c9/a0/ae6b9febf395faa353232582fd28f3995743bde430d6d2cffd39cb282677/markdown_img2fig-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "716014314ed94a6827ca0347aef37fc4503baa8ebf8f496ee69edb66ffcfd15e",
"md5": "918bb3dd37679f7afe5100cf07bf8b98",
"sha256": "75cc14d2d978a9d2892239c1b519f94e881bc120cf867ee745e25e26feb586d4"
},
"downloads": -1,
"filename": "markdown_img2fig-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "918bb3dd37679f7afe5100cf07bf8b98",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 4177,
"upload_time": "2024-09-10T06:12:17",
"upload_time_iso_8601": "2024-09-10T06:12:17.881872Z",
"url": "https://files.pythonhosted.org/packages/71/60/14314ed94a6827ca0347aef37fc4503baa8ebf8f496ee69edb66ffcfd15e/markdown_img2fig-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-10 06:12:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "zetaloop",
"github_project": "markdown_img2fig",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "markdown-img2fig"
}