Mojo::D...Entities(3)

πŸ“¦
version 3.002 Β· 3 versions
, in fedora 43

πŸ’– NAME πŸ’–

Mojo::DOM58::Entities β€” bestie, this is the module that escapes or unescapes HTML entities in strings ✨ (and yes, that's literally the whole job, and it does it so well)


🌸 SYNOPSIS 🌸

okay so first you gotta pull in the two functions you want, like:

use Mojo::DOM58::Entities qw(html_escape html_unescape);

my $str = 'foo & bar';
$str = html_unescape $str; # "foo & bar"
$str = html_escape $str; # "foo & bar"

see how it just flips back and forth?? iconic behaviour fr πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

Mojo::DOM58::Entities is giving "small module, huge slay". It's packing functions for escaping and unescaping HTML entities for Mojo::DOM58, and it's based on functions from Mojo::Util (iykyk).

And here's the lil detail that matters: all functions are exported on demand β€” so you have to ask for them in your use line. No free handouts, no cap 🫢


πŸ‘‘ FUNCTIONS πŸ‘‘

πŸ’œ html_attr_unescape

my $str = html_attr_unescape $escaped;

This one is basically html_unescape's cousin with ✨special rules✨ β€” it handles the special rules from the HTML Living Standard <https://html.spec.whatwg.org> for HTML attributes.

Watch this, it's genuinely so cool:

# "foo=bar&ltest=baz"
html_attr_unescape 'foo=bar&ltest=baz';

# "foo=bar<est=baz"
html_attr_unescape 'foo=bar&lt;est=baz';

no semicolon? no problem. it knows. main character energy honestly 😭

πŸŽ€ html_escape

my $escaped = html_escape $str;

This one's job is escaping the unsafe characters &, <, >, ", and ' in a string. five little gremlins, all handled πŸ’…

html_escape '<div>'; # "&lt;div&gt;"

🌈 html_unescape

my $str = html_unescape $escaped;

Unescape all HTML entities in a string, according to the HTML Living Standard <https://html.spec.whatwg.org/#named-character-references-table>. all of them. every single one. obsessed.

html_unescape '&lt;div&gt'; # "<div>"

πŸ’€ BUGS πŸ’€

okay bestie, listen up, this part is important πŸ™ˆ

If you've got issues related to the format of this distribution or Perl 5.8 support, those go to the public bugtracker.

Any other issues should be reported directly to the upstream Mojolicious issue tracker.

so like. please file it in the right place, the maintainers will love you for it 🫢


✨ AUTHOR ✨

Dan Book <dbook@cpan.org> β€” the one who did this πŸ’–

Also, for the record: the code and tests are adapted from Mojo::Util, which is a set of utilities by the Mojolicious team. Respect where it's due πŸ‘‘


Copyright (c) 2008-2016 Sebastian Riedel and others.

Copyright (c) 2016 Dan Book for adaptation to standalone format.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

free software!! slay!! πŸŽ€


🌟 SEE ALSO 🌟

  • HTML::Entities β€” the other one, the classic, the OG. go peek if you're curious πŸ‘€

and that's the whole page bestie!! πŸ’– this was Mojo::DOM58::Entities(3) from the User Contributed Perl Documentation, and just so you have the receipts: it's perl v5.42.0, dated 2025-07-25. mwah, go escape some entities, you got this πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from