Dom

zio.blocks.html.Dom
See theDom companion object
sealed trait Dom extends Product, Serializable

A sealed algebraic data type (ADT) representing an HTML document node.

The Dom trait models HTML as an abstract syntax tree where each node is either:

  • Text content (automatically HTML-escaped during rendering)
  • An empty node (renders to nothing)
  • An Element with a tag, attributes, and child nodes

===Rendering=== Text content is HTML-escaped by default to prevent injection attacks. However, Script and Style elements intentionally render their children WITHOUT escaping, allowing inline JavaScript and CSS to be rendered as-is.

Use render for minified HTML or render(indent: Int) for pretty-printed output with N spaces per indentation level.

===Tree Operations=== The ADT supports traversal via collect, filter, find, and transform methods for navigating and transforming the tree structure.

Attributes

See also

Dom.Element for element construction

Dom.Text for text content

Dom.Empty for empty nodes

Companion
object
Source
Dom.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
class Doctype
trait Void
class VoidGeneric
trait Element
trait Cell
trait Td
class TdElement
trait Th
class ThElement
class Generic
trait Li
class LiElement
class OptElement
class Script
trait SelectChild
trait Opt
trait Optgroup
class Style
trait Tr
class TrElement
object Empty
class Text
Show all

Members list

Value members

Concrete methods

def collect(pf: PartialFunction[Dom, Dom]): List[Dom]

Collects all nodes in the tree matching the given partial function.

Collects all nodes in the tree matching the given partial function.

Traverses the entire tree in depth-first order, applying the partial function to each node and collecting matches.

Value parameters

pf

the partial function to apply; nodes that match contribute their transformed values

Attributes

Returns

a list of matching nodes (or their transformed versions)

Source
Dom.scala
def filter(predicate: Dom => Boolean): Dom

Filters the tree to keep only nodes satisfying the predicate.

Filters the tree to keep only nodes satisfying the predicate.

Removes any node for which the predicate returns false, and recursively filters children. Empty branches collapse to Empty.

Value parameters

predicate

the condition each node must satisfy

Attributes

Returns

a new tree with non-matching nodes removed

Source
Dom.scala
def find(predicate: Dom => Boolean): Option[Dom]

Finds the first node in the tree satisfying the predicate.

Finds the first node in the tree satisfying the predicate.

Traverses the tree in depth-first order and returns the first matching node.

Value parameters

predicate

the condition to search for

Attributes

Returns

Some(node) if a match is found, None otherwise

Source
Dom.scala
def isEmpty: Boolean

Checks whether this node renders to empty HTML.

Checks whether this node renders to empty HTML.

Returns true if the node is Empty or a Text with empty content.

Attributes

Returns

true if this node produces no output when rendered

Source
Dom.scala
def render: String

Renders the DOM tree to a minified HTML string.

Renders the DOM tree to a minified HTML string.

Text content is HTML-escaped. Script and Style elements render their children without escaping to allow inline code.

Attributes

Returns

minified HTML output with no extra whitespace

Source
Dom.scala
def render(indent: Int): String

Renders the DOM tree to a pretty-printed HTML string with indentation.

Renders the DOM tree to a pretty-printed HTML string with indentation.

Text content is HTML-escaped. Script and Style elements render their children without escaping to allow inline code.

Value parameters

indent

the number of spaces per indentation level; if <= 0, behaves like render

Attributes

Returns

formatted HTML with newlines and indentation

Source
Dom.scala
def renderMinified: String

Renders the DOM tree to a minified HTML string (alias for render).

Renders the DOM tree to a minified HTML string (alias for render).

Attributes

Returns

minified HTML output

Source
Dom.scala
def select(selector: CssSelector): DomSelection

Selects all descendant nodes matching the given CSS selector.

Selects all descendant nodes matching the given CSS selector.

Value parameters

selector

the CSS selector to match against

Attributes

Returns

a DomSelection containing all matching descendant nodes

Source
Dom.scala
def transform(f: Dom => Dom): Dom

Transforms every node in the tree using the given function.

Transforms every node in the tree using the given function.

Applies the transformation function to each node in depth-first order, then recursively transforms children of Elements. Suitable for rewriting the tree, e.g., removing nodes, modifying attributes, or simplifying structure.

Value parameters

f

the transformation function to apply to each node

Attributes

Returns

a new tree with all nodes transformed

Source
Dom.scala

Inherited methods

def productElementName(n: Int): String

The name of the n^th^ element of this product, 0-based. In the default implementation, an empty string.

The name of the n^th^ element of this product, 0-based. In the default implementation, an empty string.

Value parameters

n

the index of the element name to return

Attributes

Returns

the name of the specified element

Throws
IndexOutOfBoundsException

if the n is out of range(n < 0 || n >= productArity).

Inherited from:
Product
Source
Product.scala
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
Source
Product.scala
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
Source
Product.scala
def productPrefix: String

A string used in the toString methods of derived classes. Implementations may override this method to prepend a string prefix to the result of toString methods.

A string used in the toString methods of derived classes. Implementations may override this method to prepend a string prefix to the result of toString methods.

Attributes

Returns

in the default implementation, the empty string

Inherited from:
Product
Source
Product.scala

Inherited and Abstract methods

def canEqual(that: Any): Boolean

Checks whether this instance can possibly equal that.

Checks whether this instance can possibly equal that.

A method that should be called from every well-designed equals method that is open to be overridden in a subclass. See Programming in Scala, Chapter 28 for discussion and design.

Value parameters

that

the value being probed for possible equality

Attributes

Returns

true if this instance can possibly equal that, otherwise false

Inherited from:
Equals
Source
Equals.scala
def productArity: Int

The size of this product.

The size of this product.

Attributes

Returns

for a product A(x,,1,,, ..., x,,k,,), returns k

Inherited from:
Product
Source
Product.scala
def productElement(n: Int): Any

The n^th^ element of this product, 0-based. In other words, for a product A(x,,1,,, ..., x,,k,,), returns x,,(n+1),, where `0 = productArity).

The n^th^ element of this product, 0-based. In other words, for a product A(x,,1,,, ..., x,,k,,), returns x,,(n+1),, where `0 = productArity).

Attributes

Returns

the element n elements after the first element

Inherited from:
Product
Source
Product.scala