

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: TextNode
incomplete
2: TextNode Tests
incomplete
3: HTMLNode
incomplete
4: LeafNode
incomplete
5: ParentNode
incomplete
6: TextNode to HTMLNode
incomplete
This lesson's interactive features are locked, please to keep using them
Next, we need a way to represent HTML nodes.
Our "TextNode" class represents the various types of inline text that can exist in HTML and Markdown.
Our "HTMLNode" class will represent a "node" in an HTML document tree (like a <p> tag and its contents, or an <a> tag and its contents). It can be block level or inline, and is designed to only output HTML.
tag - A string representing the HTML tag name (e.g. "p", "a", "h1", etc.)
value - A string representing the value of the HTML tag (e.g. the text inside a paragraph)
children - A list of HTMLNode objects representing the children of this node
props - A dictionary of key-value pairs representing the attributes of the HTML tag. For example, a link (<a> tag) might have {"href": "https://www.google.com"}
An HTMLNode without a tag will just render as raw text
An HTMLNode without a value will be assumed to have children
An HTMLNode without children will be assumed to have a value
An HTMLNode without props simply won't have any attributes
{
"href": "https://www.google.com",
"target": "_blank",
}Then self.props_to_html() should return:
href="https://www.google.com" target="_blank"Notice the leading space character before href and before target. This is important. HTML attributes are always separated by spaces. If self.props is None or empty, return an empty string.
Run and submit the CLI tests.