Markdown Number Title
Automatically add hierarchical numbers to Markdown headings whenever a file is saved.
中文说明
Features
- Numbers ATX headings (
# through ######) on save.
- Keeps H1 as the unnumbered document title by default.
- Produces hierarchical numbers such as
1., 1.1., and 1.1.1..
- Recalculates existing generated numbers, so repeated saves are idempotent.
- Ignores fenced code blocks, front matter, HTML comments, and
script, pre, or style blocks.
- Includes commands to update or remove numbers manually.
- Has no runtime dependencies and does not send document data outside VS Code.
Example
Before saving:
# First-level heading
## Second-level heading
### Third-level heading
## Another second-level heading
After saving:
# First-level heading
## 1. Second-level heading
### 1.1. Third-level heading
## 2. Another second-level heading
The extension updates the open Markdown document before VS Code writes it, so the original file is overwritten with the numbered content.
Commands
Open the Command Palette and run:
Markdown Number Title: Update Heading Numbers
Markdown Number Title: Remove Heading Numbers
Settings
| Setting |
Default |
Description |
markdownNumberTitle.numberOnSave |
true |
Update heading numbers before each save. |
markdownNumberTitle.startLevel |
2 |
First heading level to number. |
markdownNumberTitle.maxLevel |
6 |
Deepest heading level to number. |
To number H1 as well:
{
"markdownNumberTitle.startLevel": 1
}
Local Development
npm install
npm test
Open this repository in VS Code and press F5 to launch an Extension Development Host.
To link the source checkout into local VS Code and Cursor extension directories:
./install.sh
Package and Publish
npm run package
npm run publish
Publishing uses the official @vscode/vsce tool and the jarvanstack Marketplace publisher.
License
MIT