Skip to content

Instantly share code, notes, and snippets.

@evan-brass
Created December 25, 2020 22:17
Show Gist options
  • Save evan-brass/a2c77b0293038148ddb1a9863d860f80 to your computer and use it in GitHub Desktop.
Save evan-brass/a2c77b0293038148ddb1a9863d860f80 to your computer and use it in GitHub Desktop.
Step 3:
// 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
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment