Inline local images as base64
Goal: Make a document self-contained by embedding its local image files directly into it as data: URIs, handy for pasting a doc somewhere that can’t resolve relative image paths (a Slack message, a single-file export).
Prerequisites: The --allow-read flag, since this reads image files from disk. Only local images are touched; URLs with a scheme (https://, …) or already-data: URIs are left alone.
Query
$ mq --allow-read=. 'select(.image) | embed_images(., ".")' doc.md
Input


Output


Notes
- Unlike most mq functions,
embed_imagestakes the node as an explicit first argument, not implicitly through the pipe:embed_images(., base_dir), notembed_images(base_dir)alone. Calling it asembed_images(base_dir)silently returnsbase_diritself instead of erroring, which is easy to miss. - The base directory (second argument, default
".") is where relative image paths likelogo.pngare resolved from. It’s usually the directory containing the Markdown file, not the current working directory, if they differ. - Combine with
-Uto keep the rest of the document (non-image nodes) intact in the output.