<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    HTML::HTML5::Outline - implementation of the HTML5 Outline algorithm

SYNOPSIS
            use JSON;
            use HTML::HTML5::Outline;
        
            my $html = &lt;&lt;'HTML';
            &lt;!doctype html&gt;
            &lt;h1&gt;Hello&lt;/h1&gt;
            &lt;h2&gt;World&lt;/h2&gt;
            &lt;h1&gt;Good Morning&lt;/h1&gt;
            &lt;h2&gt;Vietnam&lt;/h2&gt;
            HTML
        
            my $outline = HTML::HTML5::Outline-&gt;new($html);
            print to_json($outline-&gt;to_hashref, {pretty=&gt;1,canonical=&gt;1});

DESCRIPTION
    This is an implementation of the HTML5 Outline algorithm, as per
    &lt;http://www.w3.org/TR/html5/sections.html#outlines&gt;.

    The module can output a JSON-friendly hashref, or an RDF model.

  Constructor
    *   "HTML::HTML5::Outline-&gt;new($html, %options)"

        Construct a new outline. $html is the HTML to generate an outline
        from, either as an HTML or XHTML string, or as an
        XML::LibXML::Document object.

        Options:

        *   default_language - default language to assume text is in when no
            lang/xml:lang attribute is available. e.g. 'en-gb'.

        *   element_subjects - rather advanced feature that doesn't bear
            explaining. See USE WITH RDF::RDFA::PARSER for an example.

        *   microformats - support "&lt;ul class="xoxo"&gt;", "&lt;ol class="xoxo"&gt;"
            and "&lt;whatever class="figure"&gt;" as sectioning elements (like
            "&lt;section&gt;", "&lt;figure&gt;", etc). Boolean, defaults to false.

        *   parser - 'html' (default) or 'xml' - choose the parser to use
            for XHTML/HTML. If the constructor is passed an
            XML::LibXML::Document, this is ignored.

        *   suppress_collections - allows rdf:List stuff to be suppressed
            from RDF output. RDF output - especially in Turtle format -
            looks somewhat nicer without them, but if you care about the
            order of headings and sections, then you'll want them. Boolean,
            defaults to false.

        *   uri - the document URI for resolving relative URI references.
            Only really used by the RDF output.

  Methods
    *   "to_hashref"

        Returns data as a nested hashref/arrayref structure. Dump it as JSON
        and you'll figure out the format pretty easily.

    *   "to_rdf"

        Returns data as a n RDF::Trine::Model. If RDF::Trine is not
        installed, dies.

    *   "primary_outlinee"

        Returns a HTML::HTML5::Outline::Outlinee element representing the
        outline for the page.

USE WITH RDF::RDFA::PARSER
    This module produces RDF data where many of the resources described are
    HTML elements. RDFa data typically does not, but RDF::RDFa::Parser does
    also support some extensions to RDFa which do (e.g. support for the
    "cite" and "role" attributes). It's useful to combine the RDF data from
    each, and RDF::RDFa::Parser 1.093 and upwards contains a few shims to
    make this possible.

    Without further ado...

            use HTML::HTML5::Outline;
            use RDF::RDFa::Parser 1.093;
            use RDF::TrineShortcuts;

            my $rdfa = RDF::RDFa::Parser-&gt;new(
                    $html_source,
                    $base_url,
                    RDF::RDFa::Parser::Config-&gt;new(
                            'html5', '1.1',
                            role_attr     =&gt; 1,
                            cite_attr     =&gt; 1,
                            longdesc_attr =&gt; 1,
                            ),
                    )-&gt;consume;
        
            my $outline = HTML::HTML5::Outline-&gt;new(
                    $rdfa-&gt;dom,
                    uri              =&gt; $rdfa-&gt;uri,
                    element_subjects =&gt; $rdfa-&gt;element_subjects,
                    );
        
            # Merging two graphs is pretty complicated in RDF::Trine
            # but a little easier with RDF::TrineShortcuts...
            my $combined = rdf_parse();
            rdf_parse($rdfa-&gt;graph,     model =&gt; $combined);
            rdf_parse($outline-&gt;to_rdf, model =&gt; $combined);
        
            my $NS = {
                    dc    =&gt; 'http://purl.org/dc/terms/',
                    o     =&gt; 'http://ontologi.es/outline#',
                    type  =&gt; 'http://purl.org/dc/dcmitype/',
                    xs    =&gt; 'http://www.w3.org/2001/XMLSchema#',
                    xhv   =&gt; 'http://www.w3.org/1999/xhtml/vocab#',
                    };
        
            print rdf_string($combined =&gt; 'Turtle', namespaces =&gt; $NS);

SEE ALSO
    HTML::HTML5::Outline::Outlinee, HTML::HTML5::Outline::Section.

    HTML::HTML5::Parser, HTML::HTML5::Sanity.

    RDF::RDFa::Parser, HTML::HTML5::Microdata::Parser, HTML::Microformats,
    HTML::Embedded::Turtle.

    RDF::Trine, RDF::Query, RDF::TrineShortcuts.

    &lt;http://www.perlrdf.org/&gt;.

AUTHOR
    Toby Inkster, &lt;tobyink@cpan.org&gt;

ACKNOWLEDGEMENTS
    This module is a fork of the document structure parser from Swignition
    &lt;http://buzzword.org.uk/swignition/&gt;.

    That in turn includes the following credits: thanks to Ryan King and
    Geoffrey Sneddon for pointing me towards [the HTML5] algorithm. I also
    used Geoffrey's python implementation as a crib sheet to help me figure
    out what was supposed to happen when the HTML5 spec was ambiguous.

COPYRIGHT AND LICENCE
    Copyright (C) 2008-2011 by Toby Inkster

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

</pre></body></html>