Appearance
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
Type | Description |
---|---|
ImmutableHtmlElementNode | Represents HTML element nodes with tags, attributes, and styles |
ImmutableHtmlTextNode | Represents text content within HTML elements |
Base Inheritance
All HTML nodes extend from:
BaseImmutableNode<ImmutableHtmlNode>
- Common node operationsBaseImmutableHtmlNode
- HTML-specific base operations
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();