md-list-tree-parser
parse markdown list-style tree to json
usage
write your tree list with -
and two spaces * n at front and one space after -
for each tree-level in your tree.md
- [level1](someurl)
- [level2](someurl)
- [another level2](someurl)
- [three](....)
- [four]()
- [four]
- [five]
- [no url]
- [parse to json](url)
- [another level2](url)
then in your js
var parser = require('md-list-tree-parser')
var json = parser('./tree.md')
output
[
{
"title": "level1",
"link": "someurl",
"children": [
{
"title": "level2",
"link": "someurl"
},
{
"title": "another level2",
"link": "someurl",
"children": [
{
"title": "three",
"link": "....",
"children": [
{
"title": "four",
"link": ""
},
{
"title": "four",
"children": [
{
"title": "five"
}
]
}
]
}
]
}
]
},
{
"title": "no url",
"children": [
{
"title": "parse to json",
"link": "url"
},
{
"title": "another level2",
"link": "url"
}
]
}
]
more usage
var parser = require('md-list-tree-parser')
var content = $('#tree').text()
var json = parser(content, 'content')