mq: jq for Markdown

Canonical version: mq: jq for Markdown.

If you've ever loved jq for slicing JSON and wished you had the same thing for Markdown, mq is exactly that.

mq is a command-line tool that queries, filters, and transforms Markdown using a jq-inspired syntax. Instead of grepping and sed-ing raw text, you address a document by its actual structure ; headings, code blocks, links, lists, tables ; and map or filter over those elements.

Markdown processing for LLM workflows

Large Language Models (LLMs) both consume and emit Markdown constantly. That makes a structure-aware Markdown processor useful: cleaning model output, extracting just the code blocks, pulling every heading into an outline, stripping a doc down to the sections you care about before feeding it back to a model.

A few examples of mq queries:

  • .h ; grab every heading
  • .code("rust") ; filter to Rust code blocks only
  • convert a CSV into a Markdown table, and back

Why I like it

  • It's jq for a format that actually dominates my day. The query mindset transfers directly. If you think in jq, you're productive in minutes.
  • It's fast. Written in Rust, with great performance, so batch-processing thousands of files is quick.
  • It has editor and CI tooling. A REPL, a VSCode extension, Neovim and Zed support, LSP, an experimental debugger, and GitHub Actions integration. It extends git-style by dropping mq-* executables on your PATH.
  • Easy to install. Curl script, Cargo, Homebrew, Docker, or pre-built binaries for macOS, Linux, and Windows. MIT-licensed.

grep, sed, and awk don't know about Markdown structure, and Pandoc converts whole documents between formats. mq queries and transforms elements within a Markdown document. I recommend it if you process docs or build LLM pipelines.

References


About Sébastien

Ready to get to the next level?

Found this valuable? Share it with someone who needs it.

Join 6,000+ readers. Get practical systems for knowledge & AI. Free.

Subscribe ✨

Free: Knowledge System Checklist

A clear roadmap to building your own knowledge system. Subscribe and get it straight to your inbox.

6,000+ readers. No spam. Unsubscribe anytime.

Subscribe