-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo-md.pegjs
43 lines (33 loc) · 1.17 KB
/
todo-md.pegjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{{
function makeLiteral(s) {
return s.join("");
}
function makeTriChecked(c) {
if (c===" ") return false;
if (c==="x") return true;
if (c==="-") return -0;
return undefined;
}
}}
Sections
= ([^#] [^\n\r]* br)* s:Section+ { return s }
Section
= header:Header br+ todos:Todos { return Object.assign(header, {description: "", todos: todos}) }
/ header:Header br+ desc:Description todos:Todos { return Object.assign(header, {description: desc, todos: todos}) }
/ header:Header br+ desc:Description { return Object.assign(header, {description: desc, todos: []}) }
/ header:Header br? { return Object.assign(header, {description: "", todos: []}) }
Header
= l:[#]+ _ t:[^#\n\r]+ { return { level: l.length, header: makeLiteral(t).trim() } }
Todos
= Todo+
Todo
= "- [" c:[ |x|-] "]" _? t:[^\n\r]* br* { return {checked: makeTriChecked(c), text: makeLiteral(t).trim()}}
Description
= lines:Line+ { return lines.join("\n").trim() }
Line
= (!"- [") (!"#") d:[^\n\r]+ br? { return makeLiteral(d) }
/ br { return "" }
_ "whitespace"
= [ ]
br "new line"
= [\n\r]