DOKK / manpages / debian 12 / libmojolicious-perl / Mojo::DOM::HTML.3pm.en
Mojo::DOM::HTML(3pm) User Contributed Perl Documentation Mojo::DOM::HTML(3pm)

Mojo::DOM::HTML - HTML/XML engine

  use Mojo::DOM::HTML;
  # Turn HTML into DOM tree
  my $html = Mojo::DOM::HTML->new;
  $html->parse('<div><p id="a">Test</p><p id="b">123</p></div>');
  my $tree = $html->tree;

Mojo::DOM::HTML is the HTML/XML engine used by Mojo::DOM, based on the HTML Living Standard <https://html.spec.whatwg.org> and the Extensible Markup Language (XML) 1.0 <https://www.w3.org/TR/xml/>.

Mojo::DOM::HTML implements the following functions, which can be imported individually.

  my $str = tag_to_html 'div', id => 'foo', 'safe content';

Generate HTML/XML tag and render it right away. This is a significantly faster alternative to "tag" for template systems that have to generate a lot of tags.

Mojo::DOM::HTML implements the following attributes.

  my $tree = $html->tree;
  $html    = $html->tree(['root']);

Document Object Model. Note that this structure should only be used very carefully since it is very dynamic.

  my $bool = $html->xml;
  $html    = $html->xml($bool);

Disable HTML semantics in parser and activate case-sensitivity, defaults to auto-detection based on XML declarations.

Mojo::DOM::HTML inherits all methods from Mojo::Base and implements the following new ones.

  $html = $html->parse('<foo bar="baz">I ♥ Mojolicious!</foo>');

Parse HTML/XML fragment.

  my $str = $html->render;

Render DOM to HTML/XML.

  $html = $html->tag('div', id => 'foo', 'safe content');

Generate HTML/XML tag.

Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.

2022-12-22 perl v5.36.0