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.
Parsing comments
From the course: Vanilla JavaScript: Building on the Document Object Model (DOM)
Parsing comments
- Now that we have a basic parsing loop implemented, we need to start recognizing different types of HTML markup. And the simplest type of markup to recognize is the HTML comments. So let's start there. Let's go back to our browser briefly. And in our HTML sample, you can see we have a comment right here at the very beginning, and it consists of this opening tag syntax here, which is a less than bang dash dash. And it's ended with dash dash greater than 10. And there are some more complicated rules about comments, but we're not going to mess with them. We're just going to stick with this. So let's go back to our code and in our parsing loop here, we're going to just add an if statement. So what we can do is if we find this opening token, so we're going to use the lexer consume a match so remember consume match looks for a token, and then it will actually discard that token if it finds it, but it'll return true. So we will…
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
-
-
-