We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

HTMLNode

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.

Assignment

    • 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.