HTML-Zoom-Parser-HH5P

 view release on metacpan or  search on metacpan

lib/HTML/Zoom/Parser/HH5P.pm  view on Meta::CPAN

			);
		}
		$handler->({
			type       => EVENT_DTD,
			%dtd,
		}) if $dtd{raw};
		
		$continuation->($self, $_, $handler, $continuation)
			for $node->childNodes;
	}
	elsif ($type == XML_DOCUMENT_FRAG_NODE)
	{
		$continuation->($self, $_, $handler, $continuation)
			for $node->childNodes;
	}
	else
	{
		warn "OTHER: $type";
		$handler->({
			type       => EVENT_OTHER,
			libxml     => $node,
			raw        => $node->toString,
		});
	}
}

sub html_escape   { encode_entities($_[1]) }
sub html_unescape { decode_entities($_[1]) }

1

__END__

=head1 NAME

HTML::Zoom::Parser::HH5P - use HTML::HTML5::Parser with HTML::Zoom

=head1 SYNOPSIS

   use HTML::Zoom;
   use HTML::Zoom::Parser::HH5P;
   
   my $template = <<HTML;
   <!DOCTYPE HTML
      PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
   <html></html>
   HTML
   
   my $output = HTML::Zoom
      -> new({ zconfig => { parser => 'HTML::Zoom::Parser::HH5P' } })
      -> from_html($template)
      -> to_html;

=head1 DESCRIPTION

C<HTML::Zoom::Parser::HH5P> is glue between L<HTML::Zoom> and
L<HTML::HTML5::Parser>. It is likely to be slower than HTML::Zoom's
built in parser and L<HTML::Zoom::Parser::HTML::Parser>, but because
HTML::HTML5::Parser uses the HTML5 parsing algorithm, should handle
malformed HTML in a manner more consistent with popular desktop web
browsers.

=head2 Constructor

=over

=item C<< new(%attributes) >>

Moose/Moo-style constructor function.

=back

=head2 Attributes

=over

=item C<< zconfig >>

Holds an L<HTML::Zoom::ZConfig> object. Read-only attribute, but a
separate C<with_zconfig> method id provided to set the zconfig
attribute.

=item C<< parse_as_fragment >>

Tri-state variable. If set to false, then all HTML parsed with this
object will be be treated as full HTML documents. Missing optional tags
such as C<< <head> >> and C<< <body> >> will be inferred and added to
the stream as required by the HTML5 specification. If set to true, then
all HTML parsed with the object will be treated as document fragments.
If undefined (the default), then this module will attempt to guess the
correct behaviour.

The current guessing heuristic is a case-insensitive search for "<html",
"<!doctype" or "<?xml" in the first 512 characters of the string being
parsed.

=item C<< ignore_implied_elements >>

Boolean. If set to true (the default) then regardless of the
C<parse_as_fragment> setting, elements which have been inferred will
not be included in the output stream.

=back

=head2 Methods

=over

=item C<< html_to_events($string) >>

Returns an arrayref of hashrefs, where each hashref represents an
"event" parsing the HTML. Events correspond to elements, text nodes,
DTDs and so on in the HTML document. (Attributes are not events, but
are included in the element hashref.)

=item C<< html_to_stream($string) >>

As per C<html_to_events> but returns an HTML::Zoom stream.

=item C<< html_escape($string) >>



( run in 1.380 second using v1.01-cache-2.11-cpan-5b529ec07f3 )