HTML-HTML5-Writer

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Home page:    <https://metacpan.org/release/HTML-HTML5-Writer>
Bug tracker:  <http://rt.cpan.org/Dist/Display.html?Queue=HTML-HTML5-Writer>
Maintainer:   Toby Inkster <mailto:tobyink@cpan.org>

0.201  2012-06-12

 - (Bugfix Documentation) Polyglot output defaults.

0.200  2012-06-12

 - Change default doctype for XHTML from DOCTYPE_HTML5 to DOCTYPE_LEGACY.
 - Default to polyglot output for XHTML.
 - Drop dependencies on parent.pm and common::sense.

0.104  2011-10-10

 - (Packaging) use Module::Package::RDF
 - (Update) use 5.010
 - Handle processing instructions, including special support for <?decode
   ...?>.

README  view on Meta::CPAN

    HTML::HTML5::Writer - output a DOM as HTML5

SYNOPSIS
     use HTML::HTML5::Writer;
 
     my $writer = HTML::HTML5::Writer->new;
     print $writer->document($dom);

DESCRIPTION
    This module outputs XML::LibXML::Node objects as HTML5 strings. It works
    well on DOM trees that represent valid HTML/XHTML documents; less well
    on other DOM trees.

  Constructor
    "$writer = HTML::HTML5::Writer->new(%opts)"
        Create a new writer object. Options include:

        *   markup

            Choose which serialisation of HTML5 to use: 'html' or 'xhtml'.

README  view on Meta::CPAN

        *   quote_attributes

            Set this to a true to force attributes to be quoted. If not
            explicitly set, the writer will automatically detect when
            attributes need quoting.

        *   voids

            Set this to true to force void elements to always be terminated
            with '/>'. If not explicitly set, they'll only be terminated
            that way in polyglot or XHTML documents.

        *   start_tags and end_tags

            Except in polyglot and XHTML documents, some elements allow
            their start and/or end tags to be omitted in certain
            circumstances. By setting these to true, you can prevent them
            from being omitted.

        *   refs

            Special characters that can't be encoded as named entities need
            to be encoded as numeric character references instead. These can
            be expressed in decimal or hexadecimal. Setting this option to
            'dec' or 'hex' allows you to choose. The default is 'hex'.

README  view on Meta::CPAN

    "$writer->should_force_start_tags"
    "$writer->should_force_end_tags"
        Booleans indicating whether optional start and end tags should be
        forced.

    "$writer->should_quote_attributes"
        Boolean indicating whether attributes need to be quoted.

    "$writer->should_slash_voids"
        Boolean indicating whether void elements should be closed in the
        XHTML style.

BUGS AND LIMITATIONS
    Certain DOM constructs cannot be output in non-XML HTML. e.g.

     my $xhtml = <<XHTML;
     <html xmlns="http://www.w3.org/1999/xhtml">
      <head><title>Test</title></head>
      <body><hr>This text is within the HR element</hr></body>
     </html>
     XHTML

lib/HTML/HTML5/Writer.pm  view on Meta::CPAN

use strict;
use HTML::HTML5::Entities 0.001 qw[];
use XML::LibXML qw[:all];

use constant {
	DOCTYPE_NIL              => '',
	DOCTYPE_HTML32           => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
	DOCTYPE_HTML4            => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
	DOCTYPE_HTML5            => '<!DOCTYPE html>',
	DOCTYPE_LEGACY           => '<!DOCTYPE html SYSTEM "about:legacy-compat">',
	DOCTYPE_XHTML1           => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
	DOCTYPE_XHTML11          => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
	DOCTYPE_XHTML_BASIC      => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
	DOCTYPE_XHTML_RDFA       => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
	DOCTYPE_HTML2            => '<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">',
	DOCTYPE_HTML40           => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/strict.dtd">',
	DOCTYPE_HTML40_STRICT    => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/strict.dtd">',
	DOCTYPE_HTML40_LOOSE     => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">',
	DOCTYPE_HTML40_FRAMESET  => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/frameset.dtd">',
	DOCTYPE_HTML401          => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
	DOCTYPE_HTML401_STRICT   => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
	DOCTYPE_HTML401_LOOSE    => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
	DOCTYPE_HTML401_FRAMESET => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
	DOCTYPE_XHTML1_STRICT    => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
	DOCTYPE_XHTML1_LOOSE     => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
	DOCTYPE_XHTML1_FRAMESET  => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
	DOCTYPE_XHTML_MATHML_SVG => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
	DOCTYPE_XHTML_BASIC_10   => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
	DOCTYPE_XHTML_BASIC_11   => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
	DOCTYPE_HTML4_RDFA       => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/html401-rdfa11-1.dtd">',
	DOCTYPE_HTML401_RDFA11   => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/html401-rdfa11-1.dtd">',
	DOCTYPE_HTML401_RDFA10   => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/html401-rdfa-1.dtd">',
	DOCTYPE_XHTML_RDFA10     => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
	DOCTYPE_XHTML_RDFA11     => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
};

our $VERSION = '0.201';

our %EXPORT_TAGS = (

lib/HTML/HTML5/Writer.pm  view on Meta::CPAN


=item * B<quote_attributes>

Set this to a true to force attributes to be quoted. If not explicitly
set, the writer will automatically detect when attributes need quoting.

=item * B<voids>

Set this to true to force void elements to always be terminated with '/>'.
If not explicitly set, they'll only be terminated that way in polyglot or
XHTML documents.

=item * B<start_tags> and B<end_tags>

Except in polyglot and XHTML documents, some elements allow their
start and/or end tags to be omitted in certain circumstances. By
setting these to true, you can prevent them from being omitted.

=item * B<refs>

Special characters that can't be encoded as named entities need
to be encoded as numeric character references instead. These
can be expressed in decimal or hexadecimal. Setting this option to
'dec' or 'hex' allows you to choose. The default is 'hex'.

lib/HTML/HTML5/Writer.pm  view on Meta::CPAN

=item C<< $writer->should_force_end_tags >>

Booleans indicating whether optional start and end tags should be forced.

=item C<< $writer->should_quote_attributes >>

Boolean indicating whether attributes need to be quoted.

=item C<< $writer->should_slash_voids >>

Boolean indicating whether void elements should be closed in the XHTML style.

=back

=head1 BUGS AND LIMITATIONS

Certain DOM constructs cannot be output in non-XML HTML. e.g.

 my $xhtml = <<XHTML;
 <html xmlns="http://www.w3.org/1999/xhtml">
  <head><title>Test</title></head>

meta/changes.ttl  view on Meta::CPAN


my:project :release my:v_0-200 .
my:v_0-200
	a               :Version ;
	dc:issued       "2012-06-12"^^xsd:date ;
	:revision       "0.200"^^xsd:string ;
	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-HTML5-Writer-0.200.tar.gz> ;
	dcs:changeset [
		dcs:versus my:v_0-104 ;
		dcs:item [ rdfs:label "Drop dependencies on parent.pm and common::sense."@en ] ;
		dcs:item [ rdfs:label "Change default doctype for XHTML from DOCTYPE_HTML5 to DOCTYPE_LEGACY."@en ] ;
		dcs:item [ rdfs:label "Default to polyglot output for XHTML."@en ]
	] .

my:project :release my:v_0-201 .
my:v_0-201
	a               :Version ;
	dc:issued       "2012-06-12"^^xsd:date ;
	:revision       "0.201"^^xsd:string ;
	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/HTML-HTML5-Writer-0.201.tar.gz> ;
	dcs:changeset [

t/01basic.t  view on Meta::CPAN

<p bim='"' bum="/bat/" hidden quux=xyzzy>foo &amp; €<p>foo</p>
<table>
<thead>
<tr><th><th>
</thead>
<tbody><tr><th><td>
<tr><th><td>
</table>
HTML

is($xwriter->document($dom)."\n", <<XHTML, 'XHTML output');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>foo</title>
<style type="text/css"><![CDATA[
p { foo: "€"; }
]]></style>
</head><body><br foo="nar" />
<!-- ffooo-->
<p bim='"' bum="/bat/" hidden="" quux="xyzzy">foo &amp; €</p><p>foo</p>
<table>
<thead>
<tr><th></th><th>
</th></tr></thead>



( run in 0.525 second using v1.01-cache-2.11-cpan-49f99fa48dc )