hugo icon indicating copy to clipboard operation
hugo copied to clipboard

Distinguish autolinks in render hook

Open Rarst opened this issue 3 years ago • 2 comments

To my understanding, at the moment markdown render hooks apply equally to the three possible kinds of links in content:

  1. marked up link [example](https://example.com)
  2. autolink <https://example.com>
  3. extended autolink https://example.com

So render-link.html would fire for each one.

For the last case WordPress has popularized the convention that bare link in content is magically turned into embedded content, for services that support such.

This creates a use case where you want to hook specifically into that case and just it, without hooking into regular links.

While this is possible to try detect it with some logic (e.g. if eq .Destination .Text), I think it might be beneficial to offer an explicit way to distinguish the cases. This might be done in a ways like passing .LinkType context to the hook and/or adding more specific templates like render-link-markup.html / render-link-autolink.html / render-link-autolink-extended.html.

Thank you for considering. :)

Rarst avatar Jun 10 '22 09:06 Rarst

I would mind adding a ´LinkType`, some notes:

  • Currently both image links and ... other links receive the same struct (the same fields), so an image linke would also need a type
  • I don't the Markdown parser currently tells us if it is 2) or 3) above..

bep avatar Jun 10 '22 14:06 bep