Convert plain text list to html

Posted by morbusg on Stack Overflow See other posts from Stack Overflow or by morbusg
Published on 2010-05-20T12:48:17Z Indexed on 2010/05/20 12:50 UTC
Read the original article Hit count: 171

Filed under:
|

So I have a plain text list like this:

I am the first top-level list item
  I am his son
  Me too
Second one here
  His son
  His daughter
    I am the son of the one above
    Me too because of the indentation
  Another one

And I would like to turn that into:

<ul>
  <li>I am the first top-level list-item
    <ul>
      <li>I am his son</li>
      <li>Me too</li>
    </ul>
  </li>
  <li>Second one here
    <ul>
      <li>His son</li>
      <li>His daughter
        <ul>
          <li>I am the son of the one above</li>
          <li>Me too because of the indentation</li>
        </ul>
      </li>
      <li>Another one</li>
    </ul>
  </li>
</ul>

How would one go about doing that?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about parse