Problem, as an interviewer would state it:
"Write a minimal HTML parser converting a plain HTML string into a nested TAG TREE — no external libraries, just tracking open/close tags and building a simple tree of { tag, children } nodes."
Examples:
parseHtml("<div><p>Hello</p></div>");
// { tag: "root", children: [{ tag: "div", children: [{ tag: "p", children: [...] }] }] }
Clarifying questions expected:
- Does this need to handle real, malformed/unclosed HTML robustly, or is well-formed input a fair assumption?
- Should self-closing tags (like a real
<br/>) be handled without expecting a matching closing tag? - Should plain text content between tags become its own kind of node in the tree?
Code / implementation expected: Yes — real, direct proof against a real, nested HTML string with multiple tag levels and text content, producing the exact correct nested tree structure.