Low-level parse5 node manipulation utilities.
Parse an HTML string. If
smartis true, returns adocumentordocumentFragmentbased on the input. Otherwise, always parses it as a document.
parse(html: string, smart?: boolean): Document | DocumentFragmentParses HTML as a fragment.
createFragment(html: string): DocumentFragmentConverts an AST node into an HTML string.
stringify(node: Node): stringGet the attributes of a node as an object.
attributesOf(node: Node): Record<string, string>Set an attribute on a node.
setAttribute(node: Node, key: string, value: string): NodeGet an attribute value from a node.
getAttribute(node: Node, key: string): string | undefinedRemove an attribute from a node.
removeAttribute(node: Node, key: string): voidConvert an object of attributes into an array of attribute objects.
toAttrs(attributes: Record<string, string>): Attribute[]Create a new element node with the specified tag name.
createNode(tagName: string): ElementCreate a new text node with the specified text content.
createTextNode(text: string): TextNodeAdd a child to a node, making it the first child.
prepend(parent: ParentNode, node: ChildNode): ChildNodeAdd a child to a node, making it the last child.
append(parent: ParentNode, node: ChildNode): ChildNodeReplace a node with another node.
replace(originalNode: ChildNode, newNode: ChildNode): ChildNode | undefinedRemove a node from its parent.
remove(node: ChildNode): ChildNodeGet all the nodes in a tree as a flat array.
flatten(node: Node | Node[]): Node[]Get the text content of a node. Throws an error if the node has multiple children or non-text children.
textOf(node: ParentNode): stringSet the text content of a node.
setText(node: ParentNode, text: string): ParentNodeCheck if a string is likely a complete HTML document.
isDocument(string: string): booleanMIT License
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Copyright (c) 2025 Cezar Augusto boss@cezaraugusto.net