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
From the course: Vanilla JavaScript: Building on the Document Object Model (DOM)
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
-
-
-
-
Where does the DOM come from?3m 4s
-
(Locked)
DIY HTML parsing1m 21s
-
(Locked)
Building a firm foundation: The lexer14m 37s
-
(Locked)
Parsing text3m 32s
-
(Locked)
Parsing comments3m 40s
-
(Locked)
Parsing elements7m 16s
-
(Locked)
Parsing attributes7m 12s
-
(Locked)
Challenge: Void elements1m 2s
-
(Locked)
Solution: Void elements3m 3s
-
-
-