yshavit / mdq

like jq but for Markdown: find specific elements in a md doc
Apache License 2.0
5 stars 0 forks source link
jq markdown md querying

mdq: jq for Markdown

Code Coverage Build status Pending TODOs Ignored tests

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

Any of these will work:

  1. cargo install --git https://github.com/yshavit/mdq
  2. You can download binaries from the latest release (or any other release, of course).
  3. You can also grab the binaries from the latest build-release workflow run. You must be logged into GitHub to do that (their limitation, not mine!)

[!Tip]

  • These binaries are all built on GitHub's servers, so if you trust my code (and dependencies), and you trust GitHub, you can trust the binaries.

    See the wiki page on release binaries for information on how to verify them.

  • You'll have to chmod +x them before you can run them.

Basic Usage

# Select sections containing "usage":
$ cat example.md | mdq '# usage'

# Select sections containing "usage", and within those find all unordered list items:
$ cat example.md | mdq '# usage | -'

# ... or maybe you only want the list items containing "note":
$ cat example.md | mdq '# usage | - note'

You can select...

The foos and bars above can be:

See the tutorial for a bit more detail, and user manual for the full picture.