https://github.com/mkdoc/mklevel
Modify heading levels
https://github.com/mkdoc/mklevel
Last synced: about 1 year ago
JSON representation
Modify heading levels
- Host: GitHub
- URL: https://github.com/mkdoc/mklevel
- Owner: mkdoc
- License: other
- Archived: true
- Created: 2016-03-26T07:27:41.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-18T02:31:56.000Z (about 10 years ago)
- Last Synced: 2025-04-18T13:21:36.208Z (about 1 year ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Heading Levels
[](https://travis-ci.org/mkdoc/mklevel)
[](https://npmjs.org/package/mklevel)
[](https://coveralls.io/github/mkdoc/mklevel?branch=master)
> Indent and outdent heading levels
Increases and decreases heading levels so the structure of a document may be modified.
Useful when you have a standalone document that you wish to include in another document but the headings in the standalone document should be indented to fit the structure of the parent document.
## Install
```
npm i mklevel --save
```
For the command line interface install [mkdoc][] globally (`npm i -g mkdoc`).
---
- [Install](#install)
- [Usage](#usage)
- [Example](#example)
- [Help](#help)
- [API](#api)
- [level](#level)
- [Level](#level-1)
- [License](#license)
---
## Usage
Create the stream and write a [commonmark][] document:
```javascript
var lvl = require('mklevel')
, ast = require('mkast');
ast.src('# 1\n\n## 2\n\n### 3\n\n')
.pipe(lvl({levels: [1, 2, -1, 0, 0, 0]}))
.pipe(ast.stringify({indent: 2}))
.pipe(process.stdout);
```
## Example
Increment all heading levels:
```shell
mkcat README.md | mklevel --all=1 | mkout
```
Decrement all heading levels:
```shell
mkcat README.md | mklevel --all=-1 | mkout
```
Convert level 2 headings to level 5:
```shell
mkcat README.md | mklevel -2=3 | mkout
```
Convert level 1 and 3 headings to level 2:
```shell
mkcat README.md | mklevel -1=1 -3=-1 | mkout
```
## Help
```
mklevel [options]
Modify heading levels.
-1=[NUM] Modify level 1 headings by NUM
-2=[NUM] Modify level 2 headings by NUM
-3=[NUM] Modify level 3 headings by NUM
-4=[NUM] Modify level 4 headings by NUM
-5=[NUM] Modify level 5 headings by NUM
-6=[NUM] Modify level 6 headings by NUM
-a, --all=[NUM] Modify all headings by NUM
-h, --help Display this help and exit
--version Print the version and exit
Report bugs to https://github.com/mkdoc/mklevel/issues
```
## API
### level
```javascript
level([opts][, cb])
```
Gets the heading level stream.
See [Level](#level-1) for additional options.
Returns an output stream.
* `opts` Object processing options.
* `cb` Function callback function.
#### Options
* `input` Readable input stream.
* `output` Writable output stream.
### Level
```javascript
new Level([opts])
```
Increases and decreases heading levels.
Takes the integer values in the `levels` option and applies them by index
to the headings in the stream.
The level modifier for level one headings is at index zero in the list.
If a level modifier would take a heading level beyond the permitted 1-6
range the value is clamped, so the following is a noop:
```javascript
{levels: [-1]}
```
Because level one headings cannot be modified below one.
To convert all level one headings to level two:
```javascript
{levels: [1]}
```
To increment headings 1-4 by one:
```javascript
{levels: [1,1,1,1]}
```
To decrement all heading levels (except level 1 which cannot be
decremented):
```javascript
{all: -1}
```
* `opts` Object stream options.
#### Options
* `levels` Array list of integer level modifiers.
* `all` Number use this value for all levels.
## License
MIT
---
Created by [mkdoc](https://github.com/mkdoc/mkdoc) on March 27, 2016
[mkdoc]: https://github.com/mkdoc/mkdoc
[commonmark]: http://commonmark.org
[jshint]: http://jshint.com
[jscs]: http://jscs.info