Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Keep only sections at a given heading level

Goal: Drop deeper subsections and keep just the top-level (or any one level) sections of a document.

Prerequisites: The section module. Section functions need all document nodes at once — pass -A on the command line, or nodes in a script.

Query

$ mq -A 'section::sections | section::by_level(1)' README.md

by_level also accepts a range:

$ mq -A 'section::sections | section::by_level(1..2)' README.md

Input

# Chapter 1

Intro.

## Section 1.1

Detail.

# Chapter 2

Content.

Output (by_level(1))

# Chapter 1

Intro.

# Chapter 2

Content.

Notes

  • by_level(2) on the same input would return ## Section 1.1 only, since Chapter 1 and Chapter 2 are level 1.