Time to render some HTML strings!
A LeafNode is a type of HTMLNode that represents a single HTML tag with no children. For example, a simple <p> tag with some text inside of it:
<p>This is a paragraph of text.</p>
We call it a "leaf" node because it's a "leaf" in the tree of HTML nodes. It's a node with no children. In this next example, <p> is not a leaf node, but <b> is.
<p>
This is a paragraph. It can have a lot of text inside tbh.
<b>This is bold text.</b>
This is the last sentence.
</p>
value and tag data members should be required (even though the tag's value may be None), while props can remain optional like the HTMLNode constructor.Use the super() function to call the constructor of the HTMLNode class.
value, it should raise a ValueError. All leaf nodes must have a value.tag (e.g. it's None), the value should be returned as raw text.LeafNode("p", "This is a paragraph of text.").to_html()
"<p>This is a paragraph of text.</p>"
LeafNode("a", "Click me!", {"href": "https://www.google.com"}).to_html()
"<a href="https://www.google.com">Click me!</a>"
def test_leaf_to_html_p(self):
node = LeafNode("p", "Hello, world!")
self.assertEqual(node.to_html(), "<p>Hello, world!</p>")
Add more tests for different tag types.
Run and submit the CLI tests from the root of the project.