Skip to content

weavepage/remark-sub-sup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

remark-sub-sup

A remark plugin for subscript and superscript syntax using _{...} and ^{...}.

Why?

LaTeX-style syntax that:

  • No GFM conflict~text~ stays as strikethrough
  • Familiar — billions of documents use _{} and ^{} for sub/sup
  • Unambiguous — braces clearly delimit content

Install

npm install remark-sub-sup

Usage

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: <p>H<sub>2</sub>O and x<sup>2</sup></p>

Syntax

H_{2}O              → H<sub>2</sub>O
x^{2}               → x<sup>2</sup>
a_{i}^{j}           → a<sub>i</sub><sup>j</sup>

Nested Braces

Braces inside content are preserved:

f_{g(x)}            → f<sub>g(x)</sub>
_{a{b}c}            → <sub>a{b}c</sub>

Note: Content inside _{...} and ^{...} is treated as plain text, not parsed as Markdown.

Escaping

\_{not sub}         → _{not sub}
_{a\}b}             → <sub>a}b</sub>

Packages

This monorepo contains:

Package Purpose
micromark-extension-sub-sup Tokenizer
mdast-util-sub-sup AST utilities
remark-sub-sup Remark plugin

License

MIT

About

Subscript and superscript syntax support for micromark, mdast, and remark using _{…} and ^{…} notation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors