A markdown header sorter aimed towards developers and technical writers.
  • CSS 37.3%
  • HTML 33.8%
  • JavaScript 28.9%
Find a file
Lukas Dzenkauskas 229ddbbe4f -
2026-04-23 16:56:51 +03:00
archive - 2026-02-12 02:39:05 +02:00
assets/audio - 2026-02-12 02:34:00 +02:00
css - 2026-02-12 02:39:05 +02:00
images rework 2026-02-12 00:27:48 +02:00
js - 2026-02-12 04:40:13 +02:00
tests - 2026-02-12 02:34:00 +02:00
.gitignore Rework initial commit (almost finalized rework) 2022-08-14 02:20:20 +03:00
index.html - 2026-04-23 16:56:51 +03:00
README.md - 2026-04-23 16:56:51 +03:00
robots.txt - 2026-04-23 16:56:51 +03:00
server.js - 2026-02-12 04:40:13 +02:00
sitemap.xml - 2026-04-23 16:56:51 +03:00

Markdown header sorter

Sort markdown sections alphabetically by heading text. Use it online or run the script in Node. No build step, no dependencies.

Try it

Open the app →

Paste markdown, choose a header level (# to ######) or “All headers,” and get sections sorted AZ. Copy the result with one click.

Features

  • Recursive sort — Sort all header levels at once; nested structure is preserved and sorted at each level.
  • Single-level sort — Sort only #, ##, ###, etc., leaving other levels unchanged.
  • Live output — Result updates as you type.
  • No backend — Runs entirely in the browser (or in Node for the core logic).
  • Free and open source — No account, no install for the web app.

Format requirements

Headers are only detected when they have a blank line above and below:

# Topic

## My topic

## My other topic

Without blank lines around headers, the sorter wont see them.

Run locally

Web app

From the project root, start the included Node server (no extra packages):

node server.js

Then open http://localhost:3000 in your browser. To use another port, pass it as an argument or set PORT:

node server.js 8080
# or
PORT=8080 node server.js

Core logic (Node)

The sorting logic is in recursiveSort.js and can be used in Node:

const { sortMarkdownHeaders } = require('./js/recursiveSort.js');

const markdown = `
# B
B content

# A
A content
`;

console.log(sortMarkdownHeaders(markdown, { level: 'all' }));
// Output: # A ... # B ...

API: sortMarkdownHeaders(input, options)

  • input — Raw markdown string.
  • options.level'all' (recursive) or 16 (sort only that header level).
  • Returns the sorted markdown string.

Tests

Run the test suite (Node):

node tests/sortMarkdown.test.js

Project structure

├── index.html
├── server.js              # Local static server (node server.js)
├── css/
│   ├── normalize.css
│   └── style.css
├── js/
│   ├── recursiveSort.js   # Core: parse, sort, serialize (browser + Node)
│   └── app.js             # Page logic: examples, toolbar, persistence
├── tests/
│   └── sortMarkdown.test.js
├── images/                # Favicons, PWA icons, web manifest
├── assets/
│   └── audio/            # Easter egg audio
├── archive/             # Old backup (e.g. index-original.html)
├── sitemap.xml
└── robots.txt

Vanilla JS and CSS; no build step.

Author

Lukas Dzenkauskas
GitHub · Buy me a coffee

License

MIT (see repository for details).