Skip to content

ImmutableHtmlNode

Union type representing immutable HTML nodes in email templates.

typescript
type ImmutableHtmlNode = ImmutableHtmlElementNode | ImmutableHtmlTextNode;

Description

ImmutableHtmlNode is a union type that represents any HTML node in the template structure. It can be either an element node (tags like <div>, <p>, etc.) or a text node (text content within elements). This type is used throughout the API for HTML manipulation and querying.

Import

typescript
import { ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';

Type Members

TypeDescription
ImmutableHtmlElementNodeRepresents HTML element nodes with tags, attributes, and styles
ImmutableHtmlTextNodeRepresents text content within HTML elements

Base Inheritance

All HTML nodes extend from:

Type Guards and Casting

Determining Node Type

typescript
function processNode(node: ImmutableHtmlNode) {
    const type = node.getType();
    
    if (type === 'element') {
        // Node is ImmutableHtmlElementNode
        const element = node.asElement();
        const tagName = element.getTagName();
        console.log(`Element: ${tagName}`);
    } else if (type === 'text') {
        // Node is ImmutableHtmlTextNode
        const textNode = node.asText();
        const content = textNode.getTextContent();
        console.log(`Text: ${content}`);
    }
}

Type Casting Methods

typescript
// Cast to element node
const element: ImmutableHtmlElementNode = node.asElement();

// Cast to text node
const textNode: ImmutableHtmlTextNode = node.asText();