For the project I'm currently working on, I have been given an array of objects, each of which contains the "content" property and the "level" property. I need to convert this list to an HTML bulleted list. For example, if I was provided with the following input (shown in JSON for simplicity):
[ {content: "Hey", level: "1"},
{content: "I just met you", level: "2"},
{content: "and this is crazy", level: "2"},
{content: "but here my number", level: "1"},
{content: "call me, maybe", level: "3"} ]
I need to convert it to the following XHTML:
<ul>
<li>Hey</li>
<li>
<ul>
<li>I just met you</li>
<li>and this is crazy</li>
</ul>
</li>
<li>but here my number</li>
<li>
<ul>
<li>
<ul>
<li>call me, maybe</li>
</ul>
</li>
</ul>
</li>
</ul>
The final product will look like this:
- Hey
- I just met you.
- and this is crazy
- but here is my number
- call me, maybe ( <- one level deeper ), I donβt think I can do it in SO)
. - /, / ? #, / .