mq is a command-line tool that processes Markdown using a syntax similar to jq. It's written in Rust, allowing you to easily slice, filter, map, and transform structured data.

[!IMPORTANT] This project is under active development.
Why mq?
mq makes working with Markdown files as easy as jq makes working with JSON. It's especially useful for:
- LLM Workflows: Efficiently manipulate and process Markdown used in LLM prompts and outputs
- LLM Input Generation: Generate structured Markdown content optimized for LLM consumption, since Markdown serves as the primary input format for most language models
- Documentation Management: Extract, transform, and organize content across multiple documentation files
- Content Analysis: Quickly extract specific sections or patterns from Markdown documents
- Batch Processing: Apply consistent transformations across multiple Markdown files
Since LLM inputs are primarily in Markdown format, mq provides efficient tools for generating and processing the structured Markdown content that LLMs require.
Features
- Slice and Filter: Extract specific parts of your Markdown documents with ease.
- Map and Transform: Apply transformations to your Markdown content.
- Command-line Interface: Simple and intuitive CLI for quick operations.
- Extensibility: Easily extendable with custom functions.
- Built-in support: Filter and transform content with many built-in functions and selectors.
- REPL Support: Interactive command-line REPL for testing and experimenting.
- IDE Support: VSCode Extension and Language Server Protocol (LSP) support for custom function development.
- Debugger: Includes an experimental debugger (
mq-dbg) for inspecting and stepping through mq queries interactively. - External Subcommands: Extend mq with custom subcommands by placing executable files starting with
mq-in~/.mq/bin/.
Installation
Quick Install
|
The installer will:
- Download the latest mq binary for your platform
- Install it to
~/.mq/bin/ - Update your shell profile to add mq to your PATH
Cargo
# Install from crates.io
# Install from Github
# Latest Development Version
# Install the debugger
# Install using binstall
Binaries
You can download pre-built binaries from the GitHub releases page:
# macOS (Apple Silicon)
&&
# Linux x86_64
&&
# Linux arm64
&&
# Windows (PowerShell)
Homebrew
# Using Homebrew (macOS and Linux)
Docker
mq-lsp (Language Server)
The mq Language Server provides IDE features like completion, hover, and diagnostics for mq query files.
Quick Install
|
Cargo
# Install from crates.io
# Install from Github
# Latest Development Version
# Install using binstall
Binaries
You can download pre-built binaries from the GitHub releases page:
# macOS (Apple Silicon)
&&
# Linux x86_64
&&
# Linux arm64
&&
# Windows (PowerShell)
Visual Studio Code Extension
You can install the VSCode extension from the Visual Studio Marketplace.
Neovim
You can install the Neovim plugin by following the instructions in the mq.nvim README.
Zed
You can install the Zed extension by following the instructions in the zed-mq README.
GitHub Actions
You can use mq in your GitHub Actions workflows with the Setup mq action:
steps:
- uses: actions/checkout@v6
- uses: harehare/setup-mq@v1
- run: mq '.code' README.md
Web API
You can try mq without installing anything via the hosted REST API at https://api.mqlang.org.
The interactive API documentation (Swagger UI) is available at https://api.mqlang.org/docs.
Language Bindings
Language bindings are available for the following programming languages:
Usage
For more detailed usage and examples, refer to the documentation.
For a comprehensive collection of practical examples, see the Example Guide.
Basic usage
)
Here's a basic example of how to use mq:
# Extract all headings from a document
# Extract code blocks containing "name"
# Extract code values from code blocks
# Extract language names from code blocks
# Extract URLs from all links
# Filter table cells containing "name"
# Select lists or headers containing "name"
# Exclude JavaScript code blocks
# Convert CSV to markdown table
# Extract a section by title
# Filter sections by heading level (scalar or range)
Advanced Usage
You can chain multiple operations to perform complex transformations:
# Generate a table of contents from headings
# String interpolation
# Merge multiple files with separators
# Extract all code blocks from an HTML file
# Convert HTML to Markdown and filter headers
# Extract specific cell from a Markdown table
# Extract frontmatter metadata from markdown files:
| if ()) | )
Using with markitdown
You can combine mq with markitdown for even more powerful Markdown processing workflows:
# Extract code blocks from markdown
|
# Extract table from markdown
|
Composing Workflows with Subcommands
mq subcommands are designed to work together via Unix pipes.
# Convert Excel report to Markdown, then extract all headings
|
# Convert a Word document and extract a specific section
|
# Convert and view Markdown directly in the terminal
|
Run mq --list to see all available subcommands (built-in and external).
External Subcommands
You can extend mq with custom subcommands by placing executable files starting with mq- in ~/.mq/bin/ or anywhere in your PATH.
This makes it easy to add your own tools and workflows to mq without modifying the core binary.
External Tools
The following external tools are available to extend mq's functionality:
- mq-check - A syntax and semantic checker for mq files
- mq-conv - A CLI tool for converting various file formats to Markdown
- mq-crawler - A web crawler that extracts structured data from websites and outputs it in Markdown format
- mq-docs - A documentation generator for mq functions, macros, and selectors
- mq-edit - A terminal-based Markdown and code editor with WYSIWYG rendering and LSP support
- mq-lsp - Language Server Protocol (LSP) implementation for mq query files, providing IDE features like completion, hover, and diagnostics
- mq-mcp - Model Context Protocol (MCP) server implementation for AI assistants
- mq-open - Graphical previewer for mq
- mq-task - Task runner using mq for Markdown-based task definitions
- mq-tui - Terminal User Interface (TUI) for interactive mq query
- mq-update - Update mq binary to the latest version
- mq-view - viewer for Markdown content
AI Assistant Integration
- MCP: mq-mcp provides a Model Context Protocol server, enabling mq to be used from any MCP-compatible AI assistant.
- Skill: The processing-markdown skill adds mq-aware assistance directly to your AI coding workflow.
Support
- 🐛 Report bugs
- 💡 Request features
- ⭐ Star the project if you find it useful!
License
This project is licensed under the MIT License. See the LICENSE file for details.