Extending Goldmark

I used MMark primarily for its sub/superscript support. Now that it’s deprecated, I’d like to find a more sustainable solution. I want to write a custom Goldmark extension, but I don’t know where I’m supposed to put it so it can be seen by Hugo. Could someone point me to the appropriate documentation? Or is the process more complicated than that?

On a side note, has someone already written and published such an extension? My searches are turning up nothing, which surprises me. I can’t be the only one on the Internet who wants to use sub/superscript.

Thanks!

2 Likes

@Perlkonig did you find out how to add Goldmark extensions, so Hugo picks them up?

It doesn’t work that way. Goldmark extensions are not “plug-and-play.” You would need to fork Hugo, modify code, build, and test. Assistance with this activity is not within the scope of this support forum.

Thanks for that, J. So raw HTML tags are the only supported way to get sub/superscript in Hugo?

I’m not a fan of raw HTML within markdown. I would create a couple of shortcodes, one for superscripts, and one for subscripts.

E = mc{{< sup 2 >}} 

So. many. characters. I’m not a fan either, but the shortcode is just barely fewer characters if you strip the spaces. I just find it so bizarre that sub/superscript is so hard to accomplish in just basic Markdown. For now, I’m just sticking with MMark until I get motivated enough to fork Hugo and make it work.

I understand. For occasional use a shortcode is fine, but if have you many it’s a hassle.

Another approach…

E = mc{^2} 

Then, in your templates, use this instead of .Content:

{{ replaceRE `\{\^([^\}]*)\}` "<sup>$1</sup>" .Content | safeHTML }}

In case you were not aware, with footnotes the superscripts are automatic:

Here is the first footnote.[^1]  
Here is the second footnote.[^2]  
Here is another.[^another]

[^1]: This is the first footnote.
[^2]: This is the second footnote.
[^another]: This is another footnote.
4 Likes

Much appreciated. That’s a solution I can work with.

@jmooring I wasn’t asking with regards tup superscript/subscript specifically, but rather with regards to extensions. But did look at the code and saw how goldmark extensions are included. I did see how it works. Technically I could fork and add any extension. Thanks for the assistance. It’s given me some food for thought.

@jmooring I think I am going to use a similar replaceRE soluton as you suggested

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