remark-sub-super

1.0.20 • Public • Published

remark-sub-super Build Status Coverage Status

This plugin parses custom Markdown syntax to handle subscript and superscript. It adds new nodes types to the mdast produced by remark:

  • sub
  • sup

If you are using rehype, the stringified HTML result will be sub or sup.

Syntax

~subscript~, e.g. a~i~

^superscript^, e.g. e^x^

AST (see mdast specification)

Sub (Parent) represents a subscript text.

interface Sub <: Parent {
  type: "sub";
}

Sup (Parent) represents a superscript text.

interface Sup <: Parent {
  type: "sup";
}

For example, the following markdown:

a^x^

x~i~

Yields:

{
  type: 'paragraph',
  children: [{
    type: 'text',
    value: 'a',
    children: [{
      type: 'sup',
      children: [{
        type: 'text',
        value: 'x'
      }]
    }]
  }]
},
{
  type: 'paragraph',
  children: [{
    type: 'text',
    value: 'x',
    children: [{
      type: 'sub',
      children: [{
        type: 'text',
        value: 'i'
      }]
    }]
  }]
}

Rehype

This plugin is compatible with rehype. Sub mdast nodes will become <sub>contents</sub>, Sup mdast nodes will become <sup>contents</sup>.

Installation

npm:

npm install remark-sub-super

Usage

Dependencies:

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

const remarkSubSuper = require('remark-sub-super')

Usage:

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

License

MIT © Zeste de Savoir

Readme

Keywords

Package Sidebar

Install

npm i remark-sub-super

Weekly Downloads

3,735

Version

1.0.20

License

MIT

Unpacked Size

8.38 kB

Total Files

5

Last publish

Collaborators

  • situphen
  • talone