Created
December 25, 2020 22:17
-
-
Save evan-brass/a2c77b0293038148ddb1a9863d860f80 to your computer and use it in GitHub Desktop.
Step 3:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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