UNPKG

datocms-html-to-structured-text

Version:

Convert HTML (or a `hast` syntax tree) to a valid DatoCMS Structured Text `dast` document

30 lines 1.05 kB
import visitNode from './visit-node.js'; // visitChildren() is for visiting all the children of a node export default async function visitChildren(createNode, parentNode, context) { const nodes = parentNode.type === 'text' || parentNode.type === 'comment' || parentNode.type === 'doctype' ? [] : parentNode.children || []; let values = []; let index = -1; while (++index < nodes.length) { const result = await visitNode(createNode, nodes[index], { ...context, parentNode, }); if (result) { if (Array.isArray(result)) { const resolved = await Promise.all(result.map((nodeOrPromise) => nodeOrPromise instanceof Promise ? nodeOrPromise : Promise.resolve(nodeOrPromise))); values = values.concat(resolved); } else { values.push(result); } } } return values; } //# sourceMappingURL=visit-children.js.map