markmap-lib

NPM

Transform Markdown to data used by markmap.

Installation

$ npm install markmap-lib

Or load from CDN:

<script src="https://cdn.jsdelivr.net/npm/markmap-lib"></script>
<script>
    const { Transformer } = window.markmap;
</script>

Usage

Importing

With built-in plugins:

import { Transformer, builtInPlugins } from 'markmap-lib';

// With default plugins
const transformer = new Transformer();

// With additional plugins
const transformer = new Transformer([...builtInPlugins, myPlugin]);

Without built-in plugins (since v0.16.0):

import { Transformer } from 'markmap-lib/no-plugins';
import { pluginFrontmatter } from 'markmap-lib/plugins';

// No plugin at all
const transformer = new Transformer();

// With specified plugins
const transformer = new Transformer([pluginFrontmatter]);

Transformation

Parse Markdown and create a node tree, return the root node and a features object containing the active features during parsing.

Transform Markdown to markmap data:

// 1. transform Markdown
const { root, features } = transformer.transform(markdown);

// 2. get assets
// either get assets required by used features
const assets = transformer.getUsedAssets(features);

// or get all possible assets that could be used later
const assets = transformer.getAssets();

Now we have the data for rendering.

Next Step

Generate interactive HTML using markmap-render.

Or use it programmatically with markmap-view.