Extensions for super- and subscripts

Hi,

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?

Greetings, Georg

1 Like

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 :heavy_check_mark:
Hugo w/ Pandoc :heavy_check_mark:
Hugo w/ reStructuredText :x:
Hugo w/ Emacs Org Mode :x:
GitHub Flavored Markdown :x:
GitLab Flavored Markdown :x:
VS Code markdown preview :x:
Typora :heavy_check_mark: (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:

image

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.

1 Like

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.

1 Like

I think @Georg is the author of that one. I went with that option for my site.

And before anyone asks, yes, you can do this with the mathematics in markdown setup.

image

But…

  1. To do it without italics is a mouthful…

    Water is \(\mathrm{H_2O}\) and transparent.
    
    This is the Pythagorean \(\mathrm{a^2 + b^2 = c^2}\) theorem.
    
  2. The font is different than the adjacent text (not sure if that’s good or bad).

  3. You have to load MathJax or KaTeX JS, which seems quite heavy for something so simple.

  4. 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).

:+1:

Seems like a good idea to me.

1 Like

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.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.