Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

mdq

> 编程语言
Open source

like jq but for Markdown: find specific elements in a md doc

1.7K stars0 likes0 views
WebsiteGitHub

About

like jq but for Markdown: find specific elements in a md doc

mdq: jq for Markdown

What is mdq?

mdq aims to do for Markdown what jq does for JSON: provide an easy way to zero in on specific parts of a document.

For example, GitHub PRs are Markdown documents, and some organizations have specific templates with checklists for all reviewers to complete. Enforcing these often requires ugly regexes that are a pain to write and worse to debug. Instead, you can (for example) ask mdq for all uncompleted tasks:

mdq '- [ ]'

mdq is available under the Apache 2.0 or MIT licenses, at your option. I am open to other permissive licenses, if you have one you prefer.

Installation

[!tip] You can try mdq live in your browser at https://yshavit.github.io/mdq-playground.

To install mdq locally, any of these will work:

  1. # (Mac and Linux, with brew installed)
    brew install mdq
    
  2. docker pull yshavit/mdq
    echo 'My [example](https://github.com/yshavit/mdq) markdown' | docker run --rm -i yshavit/mdq '[]()'
    

    To use a specific release version, use yshavit/mdq:<version>. See Docker Hub for available version tags.

  3. Download binaries from the latest release (or any other release, of course).

    Mac users

    Macs quarantine downloads from the internet by default. If you get an error saying that Apple cannot check the binary for malicious software, you can remove this flag by running the following on the binary after extracting it from the artifact zip:

    xattr -d com.apple.quarantine mdq
    
    Security concerns

    The release and latest-workflow binaries are built on GitHub's servers, so if you trust my code (and dependencies), and you trust GitHub, you can trust the binaries. See https://github.com/yshavit/mdq/wiki/Release-binaries for information on how to verify them.

    Non-release builds

    You can also grab the binaries from the latest build-release workflow run. You must be logged into GitHub to do that (this is GitHub's limitation, not mine). You'll have to chmod +x them before you can run them.

  4. cargo install --git https://github.com/yshavit/mdq
    

    Requires rustc >= 1.85.1

Basic Usage

Simple example to select sections containing "usage":

cat example.md | mdq '# usage'

Use pipe (|) to chain filters together. For example, to select sections containing "usage", and within those find all unordered list items:

cat example.md | mdq '# usage | -'

The filter syntax is designed to mirror Markdown syntax. You can select...

Element Syntax
Sections # title text
Lists - unordered list item text
" 1. ordered list item text
" - [ ] uncompleted task
" - [x] completed task
" - [?] any task
Links [display text](url)
Images ``
Block quotes > block quote text
Code blocks `
…

bash if echo "$ISSUE_TEXT" | mdq -q '- [x] I have searched for existing issues' ; then ...


(The `-q` option is like grep's: it doesn't output anything to stdout, but exits 0 if any items were found, or non-0 otherwise.)

This will match:

> - [x] I have searched for existing issues

... but will fail if the checkbox is unchecked:

> - [ ] I have searched for existing issues

### Extracting a referenced ticket

Some organizations use GitHub Actions to update their ticket tracker, if a PR mentions a ticket. You can use mdq to extract the link from Markdown as JSON, and then use jq to get the URL:

```bash
TICKET_URL="$(echo "$PR_TEXT"
  | mdq --output json '# Ticket | [](^https://tickets.example.com/[A-Z]+-\d+$)'
  | jq -r '.items[].link.url')"

This will match Markdown like:

Ticket

https://tickets.example.com/PROJ-1234

Whittling down a big table

Let's say you have a table whose columns reference people in an on-call schedule, rows correspond to weeks in YYYY-MM-DD format:

On-Call Alice Bob Sam Pat
2024-01-08 x
2024-01-15 x
2024-01-22 x

To find out when Alice is on call:

cat oncall.md | mdq ':-: /On-Call|Alice/:-: *'
|  On-Call   | Alice |
|:----------:|:-----:|
| 2024-01-08 |   x   |
| 2024-01-15 |       |
| 2024-01-22 |       |

Or, to find out who's on call for the week of Jan 15:

cat oncall.md | mdq ':-: * :-: 2024-01-15'
|  On-Call   | Alice | Bob | Sam | Pat |
|:----------:|:-----:|:---:|:---:|----:|
| 2024-01-15 |       |     |  x  |     |

Development

Using mdq in your library

mdq is available as a Rust library at https://crates.io/crates/mdq. Its docs are available at https://docs.rs/mdq/latest/mdq/.

Working on mdq itself

Requires rustc >= 1.85.1

cargo build
cargo test

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustjqmarkdownmdquerying

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言