Remark plugin for subscript (_{...}) and superscript (^{...}) syntax
npm install remark-sub-supRemark plugin for subscript (_{...}) and superscript (^{...}) syntax.
``bash`
npm install remark-sub-sup
`typescript
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkSubSup from 'remark-sub-sup'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
const html = await unified()
.use(remarkParse)
.use(remarkSubSup)
.use(remarkRehype)
.use(rehypeStringify)
.process('H_{2}O and x^{2}')
// Output:
H2O and x2
Syntax
`markdown
H_{2}O → H2O
x^{2} → x2
a_{i}^{j} → aij
`$3
`markdown
f_{g(x)} → fg(x)
_{a{b}c} → a{b}c
`$3
`markdown
\_{not sub} → _{not sub}
_{a\}b} → a}b
`Why
_{...} / ^{...}?- No GFM conflict —
~text~ stays as strikethrough
- Familiar — LaTeX users know _{} and ^{}
- Unambiguous — braces clearly delimit contentRelated
micromark-extension-sub-sup — tokenizer
- mdast-util-sub-sup` — mdast utilitiesMIT