JSPM

markdown-it-compiler

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 171
  • Score
    100M100P100Q119545F
  • License MIT

Easy configurable markdown-it compiler

Package Exports

  • markdown-it-compiler

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (markdown-it-compiler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

markdown-it-compiler

Easy configurable markdown-it compiler

Installation

yarn add markdown-it-compiler

Usage

Instantiate an instance of the compiler and sequentially compile markdown to html.

const config = {...};
const compiler = new MarkdownItCompiler(config);
const doc = compiler.compile(mardownString);
const content = doc.html;

The config as follows:

  • preset - markdown-it preset name (default: 'default')
  • options - options for markdown-it, see docs
  • plugins - array of plugins to use() (see below)
  • configure - detailed configuration of markdown-it. Type: (md: MarkdownIt) => void
  • format - postprocess the html. Type: (content: Content) => string (see below)

Example:

const config = {
  options: {
    linkify: true,
    html: true,
    typographer: true
  },
  plugins: [
    'markdown-it-abbr',
    'markdown-it-anchor',
    'markdown-it-deflist',
    'markdown-it-highlightjs',
    'markdown-it-ins',
    'markdown-it-mark',
    [
      'markdown-it-plantuml',
      {
        openMarker: '```plantuml\n@startuml',
        closeMarker: '@enduml\n```'
      }
    ],
    'markdown-it-sub',
    'markdown-it-sup'
  ],
  configure(md) {
    // load custom plugins
    md.use(require('./lib/my-md-it-plugin'));
  },
  format(content) {
    if (content.attributes.layout && content.attributes.layout === 'article') {
      return `<article>${content.html}</article>`;
    }

    return content.html;
  }
};

Post-Processing

Use the format key for postprocessing. The passed content has the following structure:

  • attributes - attributes from frontmatter
  • toc - structured table of contents, see markdown-toc
  • body - the original markdown body
  • html - the already generated html