modules/html/dom.zzm

html-0.0.2 documentation

Package

Name
html
Version
0.0.2
Uploaded
2026-06-12 23:25:02
Repository
https://github.com/tobyink/zuzu-html
Dependencies
Metadata
zuzu-distribution.json
Archive
Download .tar.gz

NAME

html/dom - DOM-like classes for parsed HTML documents.

SYNOPSIS

  from html/dom import HTMLDocument;

  let doc := new HTMLDocument();
  let root := doc.createElement("html");
  doc.appendChild( doc.createDoctype() );
  doc.appendChild(root);
  root.appendChild( doc.createElement("body") );

DESCRIPTION

This module provides the pure ZuzuScript mutable DOM core used by html/parser. It intentionally mirrors the practical DOM-like API provided by std/data/xml: construction, traversal, mutation, attributes, simple selector lookup, cloning, equality, tree walking, and serialization.

HTMLTemplateElement owns an HTMLDocumentFragment returned by content(). Parsed template children live in that fragment rather than as direct children of the template element. Elements and attributes are namespace-aware for HTML, SVG, MathML, XLink, XML, and XMLNS data used by the HTML tree builder.

Documents may be created manually through constructors and HTMLDocument factory methods, or by html/parser.

EXPORTS

Classes

  • HTMLNode

    Base node class. It implements shared metadata, traversal, mutation, text content, cloning, equality, tree walking, simple selector lookup, serialization, and unsupported XPath compatibility methods.

    Core methods include nodeName, nodeType, nodeValue, setNodeValue, nodeKind, uniqueKey, unique_id, localName, namespaceURI, firstChild, lastChild, nextSibling, previousSibling, parentNode, ownerDocument, childNodes, children, hasChildNodes, appendChild, prependChild, insertBefore, replaceChild, removeChild, remove, textContent, setTextContent, normalize, cloneNode, isSameNode, isEqualNode, contains, querySelectorAll, querySelector, findnodes, findvalue, visitEach, findFirst, toHTML, toXML, and to_String.

  • HTMLDocument

    Document node class. It adds documentElement, node factories, getElementsByTagName, and getElementById. A document may contain one doctype, one element root, and comments. Text directly under a document is rejected.

    Factory methods are createElement, createElementNS, createTextNode, createComment, createDoctype, and createCDATASection. createElement("template") returns an HTMLTemplateElement. createElementNS should be used for SVG and MathML elements. The lookup methods getElementsByTagName and getElementById search the document's descendant elements.

  • HTMLElement

    Element node class. It adds tagName, id, setId, getAttribute, setAttribute, hasAttribute, removeAttribute, attributeNames, attributes, namespaced attribute methods, attributeRecords, and descendant getElementsByTagName. Namespaced attribute methods are getAttributeNS, setAttributeNS, hasAttributeNS, and removeAttributeNS. namespaceURI and localName are authoritative for HTML, SVG, and MathML elements. Attribute values are stored as strings; missing attributes return null.

  • HTMLTemplateElement, HTMLDocumentFragment

    Template elements and their content fragments. HTMLDocument's createElement("template") returns an HTMLTemplateElement. HTMLTemplateElement.content() returns the fragment containing parsed or manually inserted template contents. HTMLDocumentFragment supports the normal container operations and getElementsByTagName. Direct children of parsed templates live in content(), not in the template element's own childNodes() array.

  • HTMLText, HTMLComment, HTMLDoctype

    Text, comment, and doctype node classes. Text and comments expose data and setData. Doctypes expose name, publicId, and systemId. HTMLDoctype is normally created with HTMLDocument.createDoctype.

  • DOMNode, DOMDocument, DOMElement, DOMText,

    DOMComment, DOMDoctype

    DOM-compatible aliases implemented as subclasses of the HTML classes.

Constants

  • HTML_NAMESPACE_URI, SVG_NAMESPACE_URI, MATHML_NAMESPACE_URI,

    XLINK_NAMESPACE_URI, XML_NAMESPACE_URI, XMLNS_NAMESPACE_URI

    Namespace URI constants used by the parser and DOM namespace APIs.

LIMITATIONS

  • findnodes and findvalue throw clear unsupported errors.

    There is no XPath or ZPath strategy in this distribution.

  • querySelector and querySelectorAll support only simple

    selectors: tag names, #id, .class, and *.

    Combinators, comma lists, pseudo-classes, namespace selectors, and attribute selectors throw clear unsupported-selector errors.

  • Namespace support covers the HTML, SVG, MathML, XLink, XML, and

    XMLNS namespace URIs used by the HTML tree builder.

    Use createElementNS, setAttributeNS, getAttributeNS, hasAttributeNS, removeAttributeNS, and attributeRecords for namespace-aware code. The older attribute methods remain available and operate on serialized qualified names.

  • createCDATASection returns an HTMLText node.

    HTML documents do not have CDATA section nodes in this DOM core, but the method is provided for std/data/xml API compatibility.

  • toHTML(pretty) and toXML(pretty) accept pretty but

    currently serialize compact HTML.

    The serializer emits document children in order, doctypes, comments, escaped text and attributes, and HTML void elements without end tags.

COPYRIGHT AND LICENCE

html/dom is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.