node-html-to-json icon indicating copy to clipboard operation
node-html-to-json copied to clipboard

Return nested elements as array

Open leandroz opened this issue 8 years ago • 0 comments

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?

leandroz avatar Apr 08 '17 21:04 leandroz