-
-
Notifications
You must be signed in to change notification settings - Fork 5
Multi Format Images
Apex extends standard Markdown image syntax with attributes for serving multiple image formats (WebP, AVIF), retina variants (@2x, @3x), and automatic format discovery. It also detects video URLs and emits <video> elements instead of <img> when appropriate.
These features are available in unified, MultiMarkdown, and GFM modes.
Add @2x or @3x after the URL to generate a srcset for high-DPI displays. Apex assumes the variant has the same path with @2x or @3x inserted before the file extension (e.g. icon.png → icon@2x.png).

Inline:

Reference-style:
![Logo][logo]
[logo]: img/hero.png @2xWith IAL:
{: @2x}Output:
<img src="img/icon.png" srcset="img/icon.png 1x, img/icon@2x.png 2x" alt="Alt">Add webp or avif after the URL and Apex wraps the image in a <picture> element with the appropriate <source> tags. Browsers that support the format use it; others fall back to the main image.


Both attributes combine with @2x and @3x for retina srcsets:

Use the auto attribute to discover formats from the filesystem. When base_directory is set (e.g. from the document path or --base-directory), Apex checks for existing variants and emits <picture> or <video> with only the variants that exist.
For images, Apex looks for:
- 2x and 3x variants (e.g.
image@2x.png,image@3x.png) - WebP and AVIF versions (e.g.
image.webp,image.avif)
Using * as the extension is equivalent to auto. It scans for jpg, png, gif, webp, and avif (plus 2x and 3x variants) for images, and mp4, webm, ogg, mov, and m4v for videos.
 is equivalent to . The base filename is derived from the path; Apex discovers which formats exist on disk and generates the appropriate <picture> or <video> element.
When the image URL ends in a video extension (mp4, mov, webm, ogg, ogv, m4v), Apex emits a <video> tag instead of <img>:
Output:
<video><source src="media/demo.mp4" type="video/mp4"></video>Add format attributes to include alternative sources for broader browser support:

Apex adds <source> elements for each format. The primary URL stays as the fallback; the attributes add webm, ogg, or other formats before it.
When using auto or * with a video base filename, Apex discovers which video formats exist (mp4, webm, ogg, mov, m4v) and emits a <video> element with the appropriate <source> tags.
| Syntax | Result |
|---|---|
 |
srcset with 1x and 2x |
 |
srcset with 1x, 2x, and 3x |
 |
<picture> with WebP source |
 |
<picture> with AVIF source |
 |
WebP with retina srcset |
 |
Discovers formats from disk (requires base_directory) |
 |
Same as auto—scans image and video formats |
 |
<video> with mp4 source |
 |
<video> with webm + mp4 fallback |
-
base_directory must be set for
autoand*to discover files. It is typically set automatically when processing a file, or via--base-directoryor metadata. - Format attributes (
webp,avif,@2x,@3x) work without base_directory; they generate URLs based on naming conventions. - Video format attributes (
webm,ogg, etc.) also work without base_directory; they generate additional<source>elements from the primary URL path.
- Syntax — Full syntax reference
- Inline Attribute Lists — IAL syntax for images
Copyright 2025 Brett Terpstra, All Rights Reserved | MIT License
- Getting Started - Your first steps with Apex
- Installation - How to build and install Apex
- Usage - Basic usage examples
- Syntax - Complete syntax reference for unified mode
- Tables - Complete table syntax reference including rowspan, colspan, alignment, and captions
- Inline Attribute Lists - IALs and ALDs guide with examples
- Modes - Understanding processor modes
- Command Line Options - All CLI flags explained
-
Multi-file Documents - Combining multiple files with
--combine,--mmd-merge, and includes - Citations - Citations and bibliography guide
- Indices - Index generation with mmark and TextIndex syntax
-
Metadata Transforms - Transform metadata values with
[%key:transform] - Integrating with Pandoc - Use Apex with Pandoc for DOCX, PDF, and more
- Using Apex with Jekyll - Use the apex-ruby gem as Jekyll’s Markdown converter (untested; feedback welcome)
- Header IDs - How header IDs are generated
- C API - Programmatic API documentation
- Writing Tests - How to add tests for new features
- Xcode Integration - Using Apex in Xcode projects
- Examples - Practical usage examples
- Plugins - Plugin system, examples, and recipes
- Filters - AST filters (Pandoc-style JSON), examples, and usage
- Troubleshooting - Common issues and solutions
- Credits - Acknowledgments and links to related projects