Cookbook
The Cookbook is a collection of task-first recipes for mq. Where the Example page walks through mq’s features, each Cookbook page starts from a real problem (“I want to do X”) and gets straight to a working query.
How a recipe is structured
Every recipe follows the same four parts:
- Goal — the problem being solved, in one sentence.
- Prerequisites — anything the input or environment needs (a module import, an mq flag, a document shape).
- Query — the mq query or command to run.
- Output — the result you should see.
Selecting and filtering content
- Generate a table of contents from headings
- Extract code blocks by language
- Extract a specific row from a table
- Get the Nth item from every list
- Extract MDX components
- Extract all URLs from links
- Find images missing alt text
- Extract blockquotes as pull quotes
- Extract footnote definitions
- Find raw HTML blocks
Working with sections
- Extract a section by its heading
- Keep only sections at a given heading level
- Split a document into chunks at a heading level
- Delete a section by its heading
- Find sections that have no content
Working with tables
- Extract all tables from a document
- Add a row to a table
- Convert a Markdown table to CSV
- Convert CSV to a Markdown table
- Reshape a table between wide and long form
Functions and data
- Write a reusable custom function
- Transform, filter, and reduce arrays
- Extract frontmatter metadata
- Bump a version string across a file
- Track task-list (checkbox) progress
- Count words in a document
- Inline local images as base64
Multi-file and LLM workflows
- Merge multiple Markdown files into one stream
- Control when large file sets run in parallel
- Generate an XML sitemap from Markdown files
- Trim a document down to LLM-sized context
- Generate document statistics
Looking for a full tour of mq’s selectors and built-in functions instead? See the Example page.