Templa...ickable(3pm)

πŸ“¦
version 0.06 Β· 2 versions
  • 0.06 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.06 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Template::Plugin::Clickable πŸ’…

okay bestie, sit down, because this is one of those little Perl docs from the User Contributed Perl Documentation pile and it is, genuinely, a banger. It's Templa...ickable(3pm) (yes the name got truncated, that's just how manpages do, don't worry about it πŸ’€). Let's get into it.


🌸 NAME 🌸

Template::Plugin::Clickable β€” literally just: make URLs clickable in HTML. That's it. That's the whole job. Slay.


✨ SYNOPSIS ✨

[% USE Clickable %]
[% FILTER clickable %]
URL is http://www.tt2.org/
[% END %]

and boom, this is what you get:

URL is <a href="http://www.tt2.org/">http://www.tt2.org/</a>

not me gasping. it just does that. iconic behaviour fr fr 🫢


πŸ’– DESCRIPTION πŸ’–

Template::Plugin::Clickable is a plugin for TT (Template Toolkit, iykyk) that lets you filter your HTML and make it, uh, clickable. That's the vibe. You feed it HTML, it hands you back HTML with the links actually linky. No cap. πŸ’…


πŸŽ€ OPTIONS πŸŽ€

  • target
[% FILTER clickable target => '_blank' %]
[% message.body | html %]
[% END %]

the target option lets you set the target attribute inside your <a> links. Default is none, so if you want links popping open in a new tab, this is your girl. πŸ¦‹

  • finder_class

the finder_class option lets you swap in a different URI finder class instead of the default, which is URI::Find. Like, for example:

[% FILTER clickable finder_class => 'URI::Find::Schemeless' %]
Visit www.example.com/join right now!
[% END %]

and this will become:

Visit <a href="http://www.example.com/join">www.example.com/join</a> right now!

schemeless URLs getting found?? we love to see it. ✨


⚠️ NOTE ⚠️

okay so this is the part where we have to be careful, bestie, because there is a real trap here. πŸ™ˆ

If you use this module together with the html filter, you should be careful not to break tags or brackets around the URLs. For example, if you've got a URL in this form:

<http://www.example.com/>

then the Clickable plugin will filter it into:

<a href="http://www.example.com/"><http://www.example.com/></a>

which is bad for HTML viewing. like, genuinely bad. πŸ’€

But β€” plot twist β€” if you run your HTML filter first and then the clickable filter, you get:

&lt;<a href="http://www.example.com/&gt">http://www.example.com/&gt</a>;

and the href part on that one is wrong. so. pick your poison, I guess. 😭

You'd better try Template::Plugin::TagRescue in this case. seriously, it's the move.
[% USE Clickable -%]
[% USE TagRescue -%]
[% FILTER html_except_for('a') -%]
[% FILTER clickable -%]
<http://www.example.com/>
[%- END %]
[%- END %]

and that will give you the right format. the correct one. the chosen one. periodt. πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

Tatsuhiko Miyagawa <miyagawa@bulknews.net>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


🌈 SEE ALSO 🌈

  • Template
  • URI::Find
  • Template::Plugin::TagRescue

and that's the whole page, bestie!! this was perl v5.34.0, dated 2022-06-17, and honestly? a little legend. go make some links clickable. mwah πŸ’–πŸ’…βœ¨