The repo https://github.com/bowman2001/goldmark-supersubscript contains two Goldmark extensions for super- and subscripts and some unit tests. The syntax is documented in the README and is similar to the extensions for markdown-it.
I’ve integrated the extensions into the branch ext_supersub of my Hugo fork and wrote two integration tests. The default configuration would be SuperSub = false.
Everything seems to work, but this is the first time I’ve been working on Hugo’s source. Are you interested in adding these extensions?
I’m not voicing an opinion here, but wanted to note some compatibility findings.
example
H~2~O
a^2^ + b^2^ = c^2^
Hugo w/ AsciiDoc
Hugo w/ Pandoc
Hugo w/ reStructuredText
Hugo w/ Emacs Org Mode
GitHub Flavored Markdown
GitLab Flavored Markdown
VS Code markdown preview
Typora
(if enabled in preferences)
Goldmark’s strikethrough extension (enabled in Hugo by default) requires ~~xxx~~ for strikethrough, while the spec allows either ~xxx~ or ~~xxx~~. GitHub follows the spec, so the H2O example looks like:
The workarounds that I have seen on this forum are:
Shortcodes
Raw HTML (best compatibility, requires markup.goldmark.renderer.unsafe = true)
strings.ReplaceRE on .Content
None of which are great. I guess I really don’t have an opinion provided that it is disabled by default and doesn’t hurt performance.
Thanks, the ambiguous strike-through specification on GitHub is unfortunate. It’s not a problem in Goldmark, as you mentioned, there’s a specific unit test. But the extension should be disabled by default, and the docs would need to inform about this incompatibility.
About the performance: The syntax (and the parser) for super- and subscript are similar to the emphasis or strike-through. The only difference is a look-ahead from the opening marker to the closing marker on the same line. Because the syntax specification excludes ordinary whitespace between the markers.
Water is \(\mathrm{H_2O}\) and transparent.
This is the Pythagorean \(\mathrm{a^2 + b^2 = c^2}\) theorem.
The font is different than the adjacent text (not sure if that’s good or bad).
You have to load MathJax or KaTeX JS, which seems quite heavy for something so simple.
I have no idea how you would write Feb 6th (with th as superscript).
I’ve only found a handful of forum topics expressing a need/want for this, but it seems like a fairly simple addition (it does two things, and will only ever do two things, and the way it does those two things from a user’s perspective should never change).
Thanks a lot for your thorough investigation. Because the next release 0.123.0 is coming soon, I’m gonna wait a little before I file a feature request and attach the pull request.