Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public createDomRef(): HTMLElement {
const { toDOM } = this.node.type.spec;
if (toDOM) {
const domSpec = toDOM(this.node);
if (isString(domSpec)) {
return document.createElement(domSpec);
}
if (isDOMNode(domSpec)) {
if (!isElementDOMNode(domSpec)) {
throw new Error('Invalid HTML Element provided in the DOM Spec');
}
return domSpec;
}
// Use the outer element string to render the dom node
return document.createElement(domSpec[0]);
}
return this.node.isInline ? document.createElement('span') : document.createElement('div');
}
export const findTextNode = (node: Node, text: string): Node | undefined => {
if (isTextDOMNode(node)) {
return node;
} else if (isElementDOMNode(node)) {
for (let ch = node.firstChild; ch; ch = ch.nextSibling) {
const found = findTextNode(ch, text);
if (found) {
return found;
}
}
}
return undefined;
};