listdown
v0.1.0
Published
A simple markup language for lists.
Downloads
3
Readme
Listdown
A ~~horribly-named~~ simple markup language for lists.
Syntax
Full example
This is an example using all possible elements (tabs represented by »
):
Hello, I'm a list!
======
Item 1
» Item 1.1
» Item 1.2
» » Item 1.2.1
» » Item 1.2.2
» » Item 1.2.3 // hello, I'm a comment
» Item 1.3
Item 2
Item 3
I'm another list
======
Item a
Item b
Item c
List name
Text followed by a line break, then 3 or more dashes or 3 or more equal signs:
For instance:
Hello!
===
Hello!
---
Hello!
==================
Hello!
------------------
Regex: (.*)\n[-|=]{3,}
List items
Tree structured using tabs or 4 spaces
For instance (tabs represented by »
):
Item 1
» Item 1.1
» Item 1.2
» » Item 1.2.1
» » Item 1.2.2
» » Item 1.2.3
» Item 1.3
Item 2
Item 3
or (spaces represented by ·
):
Item 1
····Item 1.1
····Item 1.2
········Item 1.2.1
········Item 1.2.2
········Item 1.2.3
····Item 1.3
Item 2
Item 3
Regex (maybe): ^(?!.*\n---|---|.*\n===|===).*$
Comments
Comments are preceded two forward slashes:
// hello, I'm a comment
There is no multi-line comment block.
Parsing
There is an example implementation in /dist/
(global/for the browser).
Usage is as follows (also see parse.html):
<textarea id="listdown_code"><!-- text to be parsed --></textarea>
<div id="parsed"></div>
<script src="dist/listdown.js"></script>
<script>
var text = document.getElementById('listdown_code').value;
var parsed = Listdown.parse(text);
var arr = parsed.toArray(); // array of objects
var json = parsed.toJSON();
var html = parsed.toHTML({
headingLevel: 3
});
// you can also chain methods:
var html = Listdown.parse(text).toHTML();
document.getElementById('parsed').innerHTML = html;
</script>