A goldmark extension that adds superscript
syntax: ^text^ renders as <sup>text</sup>.
E=mc^2^ → E=mc<sup>2</sup>
It is implemented the same way as goldmark's built-in extension.Strikethrough
(a single-character inline delimiter with CommonMark flanking rules), so it
behaves predictably alongside the rest of goldmark.
go get github.com/matthew6s/goldmark-superscriptimport (
"github.com/yuin/goldmark"
superscript "github.com/matthew6s/goldmark-superscript"
)
md := goldmark.New(
goldmark.WithExtensions(superscript.Superscript),
)- A pair of single carets on the same line forms a superscript span:
x^2^→x<sup>2</sup>. - The text between the carets is parsed as normal inline Markdown, so it may
contain emphasis, code spans, links, etc.:
^**b**^→<sup><strong>b</strong></sup>. - Following CommonMark flanking rules, a caret directly adjacent to whitespace
does not open or close a span (
^ 2^stays literal). - A run of two or more consecutive carets (
^^) is never a delimiter. - An unmatched caret is rendered literally.
- When the extension is not registered,
^has no special meaning.
MIT — see LICENSE.