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 = config;const doc = compiler;const content = dochtml;
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' { // load custom plugins md; } { if contentattributeslayout && contentattributeslayout === 'article' return `<article></article>`; return contenthtml; };
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