-
Couldn't load subscription status.
- Fork 2
Convert Markdown Images
The convert_images tool transforms all Markdown image references () into semantic HTML <figure> blocks with captions.
It works both on single files and entire directories (recursive, e.g. manuscript/).
-
Provides semantic HTML (
<figure>+<figcaption>) for better accessibility. -
Captions are automatically taken from the image title (if present), otherwise from the alt text.
-
Keeps code snippets safe: ignores images inside fenced code blocks (```/~~~) and inline code (
`). -
Reference-style images (
![alt][id]+[id]: url "title") are fully supported. -
Designed for book projects where images need consistent and accessible formatting.
With Poetry installed and the script registered in pyproject.toml:
poetry run convert-images manuscript/chapter01.mdpoetry run convert-images manuscriptpoetry run convert-images manuscript --dry-runpoetry run convert-images manuscript --figure-class "book-figure"By default, no backups are created (we rely on Git for version control).
If you still want .bak files before overwriting:
poetry run convert-images manuscript --backupMarkdown input
Converted HTML
<figure>
<img src="images/cat.png" alt="A cute cat" />
<figcaption>
<em>Fluffy cat</em>
</figcaption>
</figure>Unit tests ensure:
-
Inline & reference-style images are converted.
-
Captions prefer the title, fallback to alt text.
-
Angle-bracket URLs (
<file with spaces.png>) are handled. -
Images in code blocks or inline code are ignored.
-
Directory recursion works across nested folders.
-
Backup handling (
--backup) works correctly.
Run all tests with Poetry:
poetry run pytest -q- π Home
- Project Initialization
- Generate Project Structure
- How to Write a Book
- Developer Workflow & Makefile
- Chapter File Generator
- Generate Images
- Convert Markdown Images
- Bulk Change File Extensions
- Restructure Chapters
- Translate Markdown with DeepL
- Translate with LM Studio
- Translation CLI Commands
- Shortcuts for Translation
- Automatic Book Export
- Shortcuts for Export
- Export HTML Chapters (Comics)
- Export to EPUB 2
- Pandoc Batch Processor
- Export HTML Books to PDF (KDP Ready)
Use this sidebar to navigate all key workflows β from setup to translation, export, and testing.