// Parse an open tag const success = pull(/^<([a-zA-Z][a-zA-Z0-9\-]*)>/, tag => { const new_tag = { tag, attributes: {}, children: [] }; cursor.children.push(new_tag); parse_content(new_tag); }) || // Parse close tag pull(/^<\/([a-zA-Z][a-zA-Z0-9\-]*)>/, tag => { if (cursor.tag.toLowerCase() !== tag.toLowerCase()) { throw new Error("Unmatched close tag"); } run = false; }) // Parse a text node || pull(/^([^<]+)/, text => { cursor.children.push({ text }); });