Skip to content

Bundles and Chapter Ordering

Sebastian Skov Nielsen edited this page Aug 1, 2026 · 1 revision

Bundles and Chapter Ordering

Chapter discovery

Leafmark treats ordinary root-level .md files as chapters. It excludes:

  • _frontmatter.md
  • _merged.md
  • dotfiles
  • files outside the active project root

Default order

If order is absent, filenames with numeric prefixes sort first by number:

01-introduction.md
02-method.md
10-conclusion.md
appendix.md

Other names follow in natural, case-insensitive filename order.

Saved order

.leafmark/config.json can store:

{
  "order": ["introduction.md", "method.md", "conclusion.md"]
}

Files named in the list are emitted first. Entries that no longer exist are ignored. Discovered files missing from the list are appended in natural order.

Run the organizer:

pnpx @skxv/leafmark order ./report

Controls:

  • ↑/↓ selects a row
  • Space grabs/releases it
  • ↑/↓ moves a grabbed row
  • Enter saves
  • q or Ctrl+C cancels

Aliases: o, organize, and organise.

One-off chapter selection

Chapter arguments bypass discovery and saved order:

pnpx @skxv/leafmark ./report introduction.md appendix.md

Only the requested existing Markdown files are built, in argument order. Duplicate names are ignored.

Bundles

A bundle is a direct subfolder of a project that contains its own project marker:

  • .leafmark/config.json
  • leafmark.json
  • _frontmatter.md

Example:

portfolio/
├── .leafmark/config.json
├── overview.md
├── client-a/
│   ├── .leafmark/config.json
│   ├── proposal.md
│   └── estimate.md
└── client-b/
    ├── _frontmatter.md
    └── report.md

Build a bundle by placing its name after the project folder:

pnpx @skxv/leafmark ./portfolio client-a

Build selected chapters inside it:

pnpx @skxv/leafmark ./portfolio client-a proposal.md

Bundle output is nested under the root output directory:

dist/client-a/client-a.pdf

The bundle uses its own config, metadata, chapter discovery, styles, citations, and path base. The parent project and package resources remain available through Pandoc's resource path.

Clone this wiki locally