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
.
~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'
}]
}]
}]
}
This plugin is compatible with rehype. Sub
mdast nodes will become <sub>contents</sub>
, Sup
mdast nodes will become <sup>contents</sup>
.
npm:
npm install remark-sub-super
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)