HTML::...utline(3pm)
π HTML::...utline(3pm) π
okay bestie, this is the page for HTML::HTML5::Outline (the man page header lowkey abbreviates it to HTML::...utline(3pm) because β¨aestheticβ¨, it lives in User Contributed Perl Documentation). buckle up, we're outlining HTML5 and it's gonna be iconic.
β¨ NAME β¨
HTML::HTML5::Outline β literally just an implementation of the HTML5 Outline algorithm. that's it, that's the whole thing, and she ate π
πΈ SYNOPSIS πΈ
use JSON;
use HTML::HTML5::Outline;
my $html = <<'HTML';
<!doctype html>
<h1>Hello</h1>
<h2>World</h2>
<h1>Good Morning</h1>
<h2>Vietnam</h2>
HTML
my $outline = HTML::HTML5::Outline->new($html);
print to_json($outline->to_hashref, {pretty=>1,canonical=>1});
no cap, that's the whole vibe right there π¦
π DESCRIPTION π
so this module is an implementation of the HTML5 Outline algorithm, exactly as laid out over at <http://www.w3.org/TR/html5/sections.html#outlines>. go read the spec if you're feeling scholarly, i believe in you π«Ά
and she can hand you back either a JSON-friendly hashref or an RDF model. versatile queen π
π§ Constructor π§
HTML::HTML5::Outline->new($html, %options)β bestie, this makes you a brand new outline.$htmlis the HTML you want an outline from, and it can be either an HTML or XHTML string, or anXML::LibXML::Documentobject. whatever's easiest for you, no judgement π
the options are:
default_languageβ the language we just assume the text is in when there's nolang/xml:langattribute anywhere to tell us. like, e.g.'en-gb'. π₯element_subjectsβ okay so this one is a rather advanced feature that honestly doesn't bear explaining. if you're curious, peek at USE WITH RDF::RDFA::PARSER below for an example. iykyk πmicroformatsβ this one's a yes/no. when it's on,<ul class="xoxo">,<ol class="xoxo">and<whatever class="figure">get treated as sectioning elements, just like<section>,<figure>, etc. it's a boolean and it defaults to false. πΈparserβ pick your parser for XHTML/HTML:'html'(that's the default) or'xml'. heads up though β if the constructor gets handed anXML::LibXML::Document, this option is just ignored entirely. πsuppress_collectionsβ this lets you suppress therdf:Liststuff from the RDF output. and ngl, RDF output β especially in Turtle format β looks somewhat nicer without them. but if you actually care about the order of headings and sections, then bestie you want them. boolean, defaults to false. β¨uriβ the document URI, used for resolving relative URI references. it's only really used by the RDF output, so don't stress about it otherwise. π
π Object Methods π
to_hashrefβ hands you back the data as a nested hashref/arrayref structure. dump it as JSON and you'll figure out the format pretty easily, fr fr. πto_rdfβ hands you back the data as anRDF::Trine::Model. this one requiresRDF::Trineto be installed. if it isn't, this method just... won't exist. that's it, that's the deal π«Άprimary_outlineeβ returns aHTML::HTML5::Outline::Outlineeelement representing the outline for the page. main character energy tbh π
π Class Methods π
has_rdfβ tells you whether theto_rdfobject method even exists. a little vibe check, if you will. β
π¦ USE WITH RDF::RDFA::PARSER π¦
okay so this module produces RDF data where lots of the resources described are HTML elements. RDFa data typically isn't like that, but RDF::RDFa::Parser does also support some extensions to RDFa that are (e.g. support for the cite and role attributes). so it's genuinely useful to combine the RDF data from each of them, and RDF::RDFa::Parser 1.093 and upwards contains a few shims to make that possible. iconic teamwork honestly π
without further ado... (bestie i love this part)
use HTML::HTML5::Outline;
use RDF::RDFa::Parser 1.093;
use RDF::TrineShortcuts;
my $rdfa = RDF::RDFa::Parser->new(
$html_source,
$base_url,
RDF::RDFa::Parser::Config->new(
'html5', '1.1',
role_attr => 1,
cite_attr => 1,
longdesc_attr => 1,
),
)->consume;
my $outline = HTML::HTML5::Outline->new(
$rdfa->dom,
uri => $rdfa->uri,
element_subjects => $rdfa->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->graph, model => $combined);
rdf_parse($outline->to_rdf, model => $combined);
my $NS = {
dc => 'http://purl.org/dc/terms/',
o => 'http://ontologi.es/outline#',
type => 'http://purl.org/dc/dcmitype/',
xs => 'http://www.w3.org/2001/XMLSchema#',
xhv => 'http://www.w3.org/1999/xhtml/vocab#',
};
print rdf_string($combined => 'Turtle', namespaces => $NS);
slay π
π SEE ALSO π
HTML::HTML5::Outline::RDF, HTML::HTML5::Outline::Outlinee, HTML::HTML5::Outline::Section.
HTML::HTML5::Parser, HTML::HTML5::Sanity.
(the whole friend group, obsessed π«Ά)
π AUTHOR π
Toby Inkster, <tobyink@cpan.org>
π ACKNOWLEDGEMENTS π
this module is a fork of the document structure parser from Swignition <http://buzzword.org.uk/swignition/>. glow-up behavior β¨
and 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. (the spec being ambiguous? shocking. never. π)
πΈ 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.
and that's the whole page bestie!! π perl v5.36.0, dated 2022-11-19 β no cap, she's still serving. go forth and outline, you absolute legend πππ¦
π¦ where this page comes from
- debian bookworm: libhtml-html5-outline-perl 0.006-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhtml-html5-outline-perl 0.006-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-html5-outline-perl 0.006-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-html5-outline-perl 0.006-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhtml-html5-outline-perl 0.006-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms