I’m using Text.ParserCombinators.Parsec and Text.XHtml to parse an input and get a HTML output.
If my input is:
* First item, First level
** First item, Second level
** Second item, Second level
* Second item, First level
My output should be:
<ul><li>First item, First level <ul><li>First item, Second level </li><li>Second item, Second level </li></ul></li><li>Second item, First level</li></ul>
I wrote this, but obviously does not work recursively
list = do{ s <- many1 item;return (olist << s) }
item = do{
(count 1 (char '*'))
;s <- manyTill anyChar newline
;return ( li << s)
}
Any ideas?
The recursion can be more than two levels.
Thanks!
Now
parse (list 1) "foo" "* a\n** a 1\n** a 2\n* b\n** b 1\n** b 2\n"will return what you asked for.Note though, that the nested lists should themselves be inside a li, for this to be valid xhtml.