A Javascript implementation of the HTML outline algorithm.
This script provides the function
void HTMLOutline(Node root);
and defines a new object type Section implementing the concept of HTML section. A section has the following properties:
parentSectionis the parent section if any,nullotherwise;childSectionsis the array of subsections;explicitis a boolean indicating whether the section is an explicit section, i.e., corresponds to a sectioning element;headingis the heading of the section: it can be a heading content element ornullif the section has an implied heading;associatedNodesis the array of all DOM nodes that are associated with the section, in algorithm order (in particular,associatedNodes[0]is a sectioning element for explicit sections).
The function HTMLOutline adds several properties to the nodes in the DOM subtree of root:
associatedSectionis the section associated with a node if any,nullotherwise;parentSectionis the parent section of a sectioning root if any,nullotherwise (this is defined in the outline algorithm);sectionListis the outline of a sectioning element, i.e., the list of its top-level sections;textis the text of a heading content element;rankis the rank of a heading content element (an integer between -6 and -1);depthis the outline depth of a heading content element which is associated with a section.