mq · jq, but for Markdown

4 months ago

You reach for jq when your data is JSON. But so much of what you work with is Markdown. READMEs, docs, the prompts and answers you trade with a language model. mq is jq, but for Markdown. Query and reshape any Markdown file, right from the shell.

Ask about this presentation

Chapters

  1. 0:00mq
  2. 0:14A query language for Markdown
  3. 0:26Your first query
  4. 0:41Compose, like a Unix pipe
  5. 0:53Transform, not just query
  6. 1:08Where it earns its place
  7. 1:25Slice Markdown from the shell
Show transcript
  1. You reach for jq when your data is JSON. But so much of what you work with is Markdown. READMEs, docs, the prompts and answers you trade with a language model. mq is jq, but for Markdown. Query and reshape any Markdown file, right from the shell.

    Slide text
    mq logo

    jq, but for Markdown

    query → filter → transform
  2. mq is a small command line tool, written in Rust, with its own tiny query language. You point a selector at a Markdown file and get back exactly the part you want. Headings, links, code blocks, tables, or task items. Install it with Homebrew.

    Slide text

    mq is a small command line tool, written in Rust, with its own tiny query language. Point a selector at a Markdown file and get back exactly the part you want · headings, links, code blocks, tables, or task items.

    brew install mq

  3. Here is your first query. Ask for the headings, and mq pulls every one out of the file. Pipe that to plain text, and you get just the words, without any Markdown syntax. Narrow the selector to the second level, and you get only those headings. A tiny query, no regular expressions, no manual parsing.

    Slide text
    $ mq '.h' hello.md
    # Hello ## Getting Started ## Features
    $ mq '.h | to_text' hello.md
    Hello Getting Started Features
    $ mq '.h2 | to_text' hello.md
    Getting Started Features
  4. Queries compose with a pipe, exactly like a Unix pipeline. Take the headings, then keep only the ones that contain a word you care about. Or pull out a single fenced code block by its language. Small pieces, chained together.

    Slide text
    $ mq '.h | select(contains("Features"))' hello.md
    ## Features
    $ mq '.code("rust")' doc.md
    ```rust fn main() { println!("hello"); } ```
  5. mq does not only read Markdown, it rewrites it. Update mode transforms the parts you match and leaves the rest of the document untouched. Here, every heading is uppercased, and nothing else moves. It converts, too. Hand it a CSV file, and mq gives you back a clean Markdown table.

    Slide text
    $ mq -U '.h | upcase()' notes.md
    ## SETUP Install the CLI first. ## USAGE Then run a query.

    It converts, too · feed it a CSV and mq hands back a clean Markdown table with csv::csv_to_markdown_table().

  6. This is where it earns its place. Batch edits across a whole folder of docs. Pulling sections out for a build step. And shaping Markdown for language models, where it is the main input and output format. Beyond the command line there is an interactive shell, a terminal app, an MCP server, and a browser playground.

    Slide text
    mq running real queries in a terminal

    Batch edits across a folder of docs · extracting sections for a build · and shaping Markdown for language models, where it is the main input and output format. Beyond the CLI: a REPL, a terminal UI, an MCP server, and a browser playground.

  7. That is mq. jq, but for Markdown. Install it with Homebrew, and run your first query in under a minute. Everything you need is at mqlang.org.

    Slide text
    • Query · pull headings, links, code, tables, tasks.
    • Compose · chain selectors with a pipe.
    • Transform · rewrite in place, convert formats.
    • Everywhere · CLI, REPL, TUI, MCP, playground.

    brew install mq

    mqlang.org

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York