1.0.0 • Published 2 years ago

remark-deflist-simple v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

remark-deflist

Built for docusaurus v2 s.t. it can be required (docusaurus is not yet ESM ready...).

Syntax

Definition 1
: Explanation 1a
: Explanation 1b

Definition 2
: Explanation 2

AST (see mdast specification)

For example, the following markdown:

Definition 1
: Explanation 1a

Yields:

{
    type: 'dl',
    data: {
        hName: 'dl'
    },
    children: [
        {
            type: 'dt',
            data: {
                hName: 'dt'
            },
            children: [{
                type: 'text',
                value: 'Definition 1'
            }]
        },
        {
            type: 'dd',
            data: {
                hName: 'dd'
            },
            children: [{
                type: 'text',
                value: 'Explanation 1a'
            }]
        }
    ]
}

Rehype

This plugin is compatible with rehype. deflist mdast nodes will become

<dl>
    <dt>Definition</dt>
    <dd>Explanation</dd>
    <dd>...</dd>
</dl>

Installation

yarn add remark-deflist-simple

Usage

Dependencies:

const unified = require('unified')
const remarkParse = require('remark-parse')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

const remarkDeflist = require('remark-deflist-simple')

Usage:

unified()
  .use(remarkParse)
  .use(remarkDeflist)
  .use(remark2rehype)
  .use(stringify)