A PostHTML plugin to transform Markdown using markdown-it
npm install posthtml-markdownit [![Version][npm-version-shield]][npm]
[![Build][github-ci-shield]][github-ci]
[![License][license-shield]][license]
[![Downloads][npm-stats-shield]][npm-stats]
This PostHTML plugin compiles Markdown to HTML using markdown-it.
Before:
``xml
# Heading 1
---
Paragraph with some text
_Italic_
Bold
- List item 1
- List item 2
- List item 3
`
After:
` Paragraph with some texthtml`Heading 1
Italic
Bold
``
npm i -D posthtml posthtml-markdownit
`js
import posthtml from 'posthtml'
import markdown from 'posthtml-markdownit'
posthtml([
markdown()
])
.process('
.then(result => console.log(result.html))
//
$3
You can import and render Markdown files:
Before:
`xml
# Imported
`After:
`html
Imported
`Syntax
$3
Both
and tags are supported.Before:
`xml
# Heading 1
`After:
`html
Heading 1
`By default, the custom tags like
are replaced with the compiled Markdown. See the tag attribute if you need a wrapping tag around your Markdown content.$3
You can also use the
markdown or md attributes on an HTML element:Before:
`html
# Heading 1
`After:
`html
Heading 1
`####
tagYou can use a
tag attribute to wrap the resulting markup in a tag:Before:
`xml
# Heading 1
`After:
`html
Heading 1
`####
inlineYou can mark the content to be rendered inline. This is helpful if you're including a file that will be used as an inline element and don't want the enclosing
p tags.Before:
`xml
Imported
`After:
`html
Imported
`Instead of:
`html
Imported
`Options
$3
Type:
string\
Default: ./A path relative to which Markdown files will be imported.
$3
Type:
string\
Default: utf8Encoding for imported Markdown files.
$3
Type:
object\
Default: {}Options passed to the
markdown-it library. See the available options.$3
Type:
array\
Default: []Plugins for
markdown-it.Example:
`js
import {light as emoji} from 'markdown-it-emoji'markdown({
plugins: [{
plugin: emoji,
options: {} // Options for markdown-it-emoji
}]
})
``[npm]: https://www.npmjs.com/package/posthtml-markdownit
[npm-version-shield]: https://img.shields.io/npm/v/posthtml-markdownit.svg
[npm-stats]: http://npm-stat.com/charts.html?package=posthtml-markdownit
[npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-markdownit.svg
[github-ci]: https://github.com/posthtml/posthtml-markdownit/actions/workflows/nodejs.yml
[github-ci-shield]: https://github.com/posthtml/posthtml-markdownit/actions/workflows/nodejs.yml/badge.svg
[license]: ./LICENSE
[license-shield]: https://img.shields.io/npm/l/posthtml-markdownit.svg