remark-definition-list
v2.0.0
Published
remark plugin to support definition list
Downloads
5,859
Maintainers
Readme
remark-definition-list
remark plugin to support definition list
Feature
- fully support Definition Lists Syntax of php-markdown
- work with rehype using remark-rehype
- shipped with types
Install
$ npm install remark-definition-list
Use
Markdown -> HTML
import { remarkDefinitionList, defListHastHandlers } from 'remark-definition-list';
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import rehypeStringify from 'rehype-stringify';
const md = `
Test for defList.
Apple
: Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.
Orange
: The fruit of an evergreen tree of the genus Citrus.
`;
const html = await unified()
.use(remarkParse)
.use(remarkDefinitionList)
.use(remarkRehype, {
handlers: {
// any other handlers
...defListHastHandlers,
}
})
.use(rehypeStringify)
.process(md);
HTML -> Markdown
import { remarkDefinitionList, defListHastToMdast } from 'remark-definition-list';
import { unified } from 'unified';
import rehypeParse from 'rehype-parse';
import rehypeRemark from 'rehype-remark';
import remarkStringify from 'remark-stringify';
const html = `
<p>Test for defList.</p>
<dl>
<dt>Apple</dt>
<dd>Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.
</dd>
<dt>Orange</dt>
<dd>The fruit of an evergreen tree of the genus Citrus.
</dd>
</dl>`;
const html2md = await unified()
.use(rehypeParse, { fragment: true })
.use(rehypeRemark, {
handlers: defListHastToMdast,
})
.use(remarkDefinitionList)
.use(remarkStringify)
.process(html);