node-html-to-json
node-html-to-json copied to clipboard
Return nested elements as array
Hi!, what I am trying to implement is parsing a ul that can have deeper levels like:
<ul>
<li><a>Title Page</a></li>
<li><a>Copyright Page</a></li>
<li><a>Dedication Page</a></li>
<li>
<a>Preface: About this edition</a>
<ul>
<li><a>#1. Let’s face it: It’s old</a></li>
<li><a>#2. The world has changed</a></li>
<li><a>Don’t get me wrong...</a></li>
</ul>
</li>
<li><a>Index</a></li>
</ul>
The idea is to get something like:
{
text: '',
href: '',
children: [
{
text: '',
href: '',
children: []
}
]
}
Any idea how to apply recursion?