yuin / goldmark-highlighting

A Syntax highlighting extension for the goldmark markdown parser.
MIT License
100 stars 14 forks source link

[feature request] Support for linkable line numbers as supported by Chroma #25

Closed kaushalmodi closed 2 years ago

kaushalmodi commented 2 years ago

Hello,

Can you please enable the support of LinkableLineNumbers() as supported by Chroma?

https://github.com/alecthomas/chroma#the-html-formatter

Hugo supported enabling the generation of linkable line numbers by passing the anchorlinenos=true attribute to the Hugo highlight shortcode. That shortcode internally uses the same Chroma library to do the code syntax highlighting.

Right now, the highlight shortcode inherits this anchorlinenos=true feature from Chroma. But if I try to use code fences with that attribute, I do not get anchorized line numbers because this library doesn't support that.

Thanks!


References

jmooring commented 2 years ago

If implemented, please remember that there may be two or more fenced code blocks in the same document. That means that the id of the element wrapping the line number must be unique to the document, not just the code block in which it occurs. Perhaps two attributes: a boolean to enable/disable, and a string to prepend to the id.

kaushalmodi commented 2 years ago

@jmooring

Perhaps two attributes: a boolean to enable/disable, and a string to prepend to the id.

Just to clarify, those would be equivalent to the anchorlinenos (boolean) and lineanchor (string) in Hugo, right?

I want to make sure that this extension doesn't auto-generate an anchor prefix if the user provides one.

jmooring commented 2 years ago

those would be equivalent to the anchorlinenos (boolean) and lineanchor (string)

Yes, but Hugo is just one of several projects that leverage yuin/goldmark and yuin/goldmark-highlighting. Implementation details need to be somewhat agnostic with respect to downstream projects.

kaushalmodi commented 2 years ago

Closing this issue here because the issue was apparently fixed in Hugo itself in https://github.com/gohugoio/hugo/commit/08fdca9d9365eaf1e496a12e2af5e18617bd0e66 .