From the course: Vanilla JavaScript: Building on the Document Object Model (DOM)

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

DIY HTML parsing

DIY HTML parsing

- [Instructor] Writing the code to convert human readable HTML source code into a browser friendly DOM tree structure, can seem overwhelming at first. There are many different approaches that can be taken, but one of the simplest to understand is a recursive descent parser. Recursive descent parser is a top-down parser, meaning that you start by writing a function that will consume the entire text to be parsed. Let's call this function ParseContent. It will be able to parse any sequence of HTML syntax we give it. While our parser could technically be built to read the input text one character at a time like a file, most real-world parsers use what is called a lexical analyzer or a lexer to make things simpler. A lexer is like a smart file interface, but instead of just returning single characters, it can recognize and return groups of characters called tokens. So our parseContent function will be able to peek at the next…

Contents