mklevel

Modify heading levels

Usage no npm install needed!

<script type="module">
  import mklevel from 'https://cdn.skypack.dev/mklevel';
</script>

README

Heading Levels

Build Status npm version Coverage Status

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).



Usage

Create the stream and write a commonmark document:

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:

mkcat README.md | mklevel --all=1 | mkout

Decrement all heading levels:

mkcat README.md | mklevel --all=-1 | mkout

Convert level 2 headings to level 5:

mkcat README.md | mklevel -2=3 | mkout

Convert level 1 and 3 headings to level 2:

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

level([opts][, cb])

Gets the heading level stream.

See Level 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

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:

{levels: [-1]}

Because level one headings cannot be modified below one.

To convert all level one headings to level two:

{levels: [1]}

To increment headings 1-4 by one:

{levels: [1,1,1,1]}

To decrement all heading levels (except level 1 which cannot be decremented):

{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 on March 27, 2016