Skip to content

Commit 1ce5624

Browse files
committed
saves multiline descriptions
1 parent 51c9a38 commit 1ce5624

File tree

2 files changed

+55
-24
lines changed

2 files changed

+55
-24
lines changed

‎parser/index.pegjs

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,87 @@
11
{
2+
// final parsed output for coderoad.json file
3+
var position = {
4+
page: -1,
5+
};
26
var output = {
37
info: {
4-
8+
title: 'Tutorial Title',
9+
description: '',
510
},
611
pages: []
12+
};
13+
14+
function adjust(item) {
15+
return item[0].concat(item[1].join(''));
716
}
817
}
918

1019
start
11-
= info
20+
= doc
1221
{ return output; }
1322

1423
doc
15-
= info
16-
page*
24+
= info_title
25+
info_description*
26+
optionalBreak
27+
page*
1728

1829
page
1930
= page_title
20-
description
31+
page_description*
2132

2233
page_title
2334
= '##'
24-
space
35+
optionalSpace
2536
title: content
2637
EOL
27-
{ return title.join(''); }
38+
{
39+
// increment page
40+
position.page += 1;
41+
// add page outline
42+
output.pages.push({
43+
title: 'Page ' + position.page,
44+
description: '',
45+
});
46+
// add page title
47+
output.pages[position.page].title = adjust(title);
48+
}
2849

29-
info
30-
= title: info_title
31-
description: description
32-
{
33-
// set info
34-
output.info.title = title;
35-
output.info.description = description
36-
}
50+
page_description
51+
= description: content
52+
EOL
53+
{
54+
const d = output.pages[position.page].description;
55+
output.pages[position.page].description += d.length > 0 ? '\n' : '';
56+
output.pages[position.page].description += adjust(description);
57+
}
3758

3859
info_title
3960
= '#'
40-
space
61+
optionalSpace
4162
title: content
42-
EOL
43-
{ return title.join(''); }
63+
{ output.info.title = adjust(title); }
4464

45-
description
65+
info_description
4666
= description: content
4767
EOL
48-
{ return description.join(''); }
68+
{
69+
const d = output.info.description;
70+
output.info.description += d.length > 0 ? '\n' : '';
71+
output.info.description += adjust(description);
72+
}
4973

50-
content = [0-9A-Za-z ]*
51-
space = [ ]
74+
content = [^#] [^\n^\r]+ [\n\r]
75+
space = [ \s]
5276
EOL = [\n\r]?
5377
file_path = [a-z_\-\s0-9\.]+
5478
quote = [\"\'\`]
5579

56-
break = space EOL
80+
optionalBreak = EOL?
81+
optionalSpace = space?
82+
83+
{
84+
// notes
85+
// - break if line starts with #
86+
// - break if line starts with @
87+
}

‎test/titles.js renamed to ‎test/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ some description
3232
t.deepEqual(result.info, expected.info);
3333
});
3434

35-
test.skip('parses a multiline description', t => {
35+
test('parses a multiline description', t => {
3636
const data = `# Title
3737
some description
3838
and more on

0 commit comments

Comments
 (0)