Skip to content

Commit 717e713

Browse files
committed
📝 docs: add section deletion cookbook and cross-link section ops
Documents the section::filter_sections() + section::collect() pattern for deleting a Markdown section by heading, which had no example in docs/ or the processing-markdown skill despite being achievable with existing built-ins.
1 parent 263120b commit 717e713

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

docs/books/src/start/example.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,51 @@ Use the tool like this.
391391

392392
**Output**: `["Introduction", "Usage"]`
393393

394+
### Delete a Section by Heading
395+
396+
Use `filter_sections()` with a negated predicate to drop sections whose title matches, then flatten back to Markdown with `collect()`:
397+
398+
```bash
399+
$ mq -A 'section::filter_sections(fn(s): section::title(s) != "Deprecated";) | section::collect()' README.md
400+
```
401+
402+
Or with `nodes`:
403+
404+
```mq
405+
import "section"
406+
| nodes
407+
| section::filter_sections(fn(s): section::title(s) != "Deprecated";)
408+
| section::collect()
409+
```
410+
411+
**Input example**:
412+
413+
```markdown
414+
# Introduction
415+
416+
Welcome to the project.
417+
418+
## Installation
419+
420+
Run the following command.
421+
422+
## Deprecated
423+
424+
Do not use this anymore.
425+
```
426+
427+
**Output**:
428+
429+
```markdown
430+
# Introduction
431+
432+
Welcome to the project.
433+
434+
## Installation
435+
436+
Run the following command.
437+
```
438+
394439
## Table Operations
395440

396441
The table module provides functions for extracting and transforming Markdown tables.

docs/llms-full.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,9 @@ mq -A 'section::sections() | section::by_level(2)' README.md
707707

708708
# Generate table of contents
709709
mq -A 'section::sections() | section::toc()' README.md
710+
711+
# Delete a section by heading
712+
mq -A 'section::filter_sections(fn(s): section::title(s) != "Deprecated";) | section::collect()' README.md
710713
```
711714

712715
## Table Operations

skills/processing-markdown/EXAMPLES.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ mq --csv 'include "csv" | csv_parse(true) | csv_to_markdown_table()' data.csv
4343
mq -I raw 'identity()' data.json # Disable auto-parse
4444
```
4545

46+
## Section Operations
47+
48+
Split/filter a document into sections by heading, then flatten back to Markdown with `section::collect()`. Needs all document nodes: use `-A` or pipe through `nodes`.
49+
50+
```bash
51+
mq -A 'section::section("Installation")' README.md # Extract section by title
52+
mq -A 'section::section("Installation") | section::bodies() | first()' README.md # Section body only (no header)
53+
mq -A 'section::sections() | section::by_level(2)' README.md # h2 sections only
54+
mq -A 'section::sections() | section::toc()' README.md # Table of contents
55+
mq -A 'section::filter_sections(fn(s): section::title(s) != "Deprecated";) | section::collect()' README.md # Delete a section by heading
56+
```
57+
58+
See [example.md](../../docs/books/src/start/example.md) for the full section reference (import/include forms, `-A` vs `nodes`, more filters).
59+
4660
## Multi-File & Aggregation
4761

4862
```bash

skills/processing-markdown/SKILL.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ mq -I html 'identity' page.html # HTML → Markdown
102102

103103
# Streaming large files
104104
mq --stream 'select(contains("ERROR"))' large.md
105+
106+
# Section operations (needs -A or `nodes` — see EXAMPLES.md)
107+
mq -A 'section::section("Installation")' file.md # Extract section by heading
108+
mq -A 'section::filter_sections(fn(s): section::title(s) != "Deprecated";) | section::collect()' file.md # Delete section by heading
105109
```
106110

107111
## HTML Input: Always Use Markdown Selectors

0 commit comments

Comments
 (0)