Scroll to navigation

Mojo::DOM58::Entities(3) User Contributed Perl Documentation Mojo::DOM58::Entities(3)

NAME

Mojo::DOM58::Entities - Escape or unescape HTML entities in strings

SYNOPSIS

  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"

DESCRIPTION

Mojo::DOM58::Entities contains functions for escaping and unescaping HTML entities for Mojo::DOM58, based on functions from Mojo::Util. All functions are exported on demand.

FUNCTIONS

html_attr_unescape

  my $str = html_attr_unescape $escaped;

Same as "html_unescape", but handles special rules from the HTML Living Standard <https://html.spec.whatwg.org> for HTML attributes.

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

html_escape

 my $escaped = html_escape $str;

Escape unsafe characters "&", "<", ">", """, and "'" in string.

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

html_unescape

 my $str = html_unescape $escaped;

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

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

BUGS

Report issues related to the format of this distribution or Perl 5.8 support to the public bugtracker. Any other issues should be reported directly to the upstream Mojolicious issue tracker.

AUTHOR

Dan Book <dbook@cpan.org>

Code and tests adapted from Mojo::Util, a set of utilities by the Mojolicious team.

COPYRIGHT AND LICENSE

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)

SEE ALSO

HTML::Entities

2021-06-17 perl v5.40.0