Skip to content

Commit 3537be5

Browse files
committed
fix: empty lines treated as line breaks
1 parent 65b6674 commit 3537be5

File tree

8 files changed

+35
-96
lines changed

8 files changed

+35
-96
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Command line interface for [CodeRoad](http://coderoad.github.io).
2929
* a `package.json` configuration with the following settings:
3030

3131
```
32-
"name": "coderoad-$my-tutorial-name$",
32+
"name": "coderoad-$TUTORIAL-NAME$",
3333
"main": "coderoad.json",
3434
"keywords": ["coderoad", "tutorial"],
3535
"coderoad": {

cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var tutorials_1 = require('./src/tutorials/tutorials');
1010
var publish_1 = require('./src/publish/publish');
1111
var docs_1 = require('./src/docs/docs');
1212
program
13-
.version('0.3.8')
13+
.version('0.3.9')
1414
.usage('[options] <keywords>')
1515
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
1616
.option('-c, --create [name]', 'tutorial name')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coderoad-cli",
3-
"version": "0.3.8",
3+
"version": "0.3.9",
44
"description": "Command line interface for CodeRoad. Build project files.",
55
"keywords": [
66
"coderoad"

src/build/parser/actions.js

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,35 @@ function trimCommandValue(text) {
1010
return command.action + '(\'' + command.value + '\')';
1111
}
1212
exports.trimCommandValue = trimCommandValue;
13+
function doAction(type, isArray, actionValue, result, line, index) {
14+
if (result.chapters[index.chapter].pages[index.page].tasks[index.task][type] === undefined) {
15+
result.chapters[index.chapter].pages[index.page].tasks[index.task][type] = [];
16+
}
17+
if (!!isArray) {
18+
var valueList = actionValue.slice(1, -1).split(',');
19+
valueList.forEach(function (value) {
20+
var value = cleanup_1.trimQuotes(value.trim());
21+
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(value);
22+
});
23+
}
24+
else {
25+
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(actionValue);
26+
}
27+
return result;
28+
}
1329
function addToTasks(result, line, index) {
1430
var match = Match.isAction(line);
1531
var action = match.action;
1632
var task = result.chapters[index.chapter].pages[index.page].tasks[index.task];
17-
var trimmedAction = line.slice(action.length + 2, line.length - 1);
18-
var actionValue = cleanup_1.trimQuotes(trimmedAction);
33+
var trimmedContent = line.slice(action.length + 2, line.length - 1);
34+
var actionValue = cleanup_1.trimQuotes(trimmedContent);
1935
var isActionArray = Match.isArray(cleanup_1.trimQuotes(actionValue));
2036
switch (action) {
2137
case 'test':
22-
if (result.chapters[index.chapter].pages[index.page].tasks[index.task].tests === undefined) {
23-
result.chapters[index.chapter].pages[index.page].tasks[index.task].tests = [];
24-
}
25-
if (!!isActionArray) {
26-
var valueList = actionValue.slice(1, -1).split(',');
27-
valueList.forEach(function (value) {
28-
var value = cleanup_1.trimQuotes(value.trim());
29-
result.chapters[index.chapter].pages[index.page].tasks[index.task].tests.push(value);
30-
});
31-
}
32-
else {
33-
result.chapters[index.chapter].pages[index.page].tasks[index.task].tests.push(actionValue);
34-
}
38+
result = doAction('tests', isActionArray, actionValue, result, line, index);
39+
break;
40+
case 'hint':
41+
result = doAction('hints', isActionArray, actionValue, result, line, index);
3542
break;
3643
case 'action':
3744
if (task.actions === undefined) {
@@ -50,21 +57,6 @@ function addToTasks(result, line, index) {
5057
}
5158
return result;
5259
break;
53-
case 'hint':
54-
if (task.hints === undefined) {
55-
result.chapters[index.chapter].pages[index.page].tasks[index.task].hints = [];
56-
}
57-
if (!!isActionArray) {
58-
var valueList = actionValue.slice(1, -1).split(',');
59-
valueList.forEach(function (value) {
60-
var value = cleanup_1.trimQuotes(value.trim());
61-
result.chapters[index.chapter].pages[index.page].tasks[index.task].hints.push(value);
62-
});
63-
}
64-
else {
65-
result.chapters[index.chapter].pages[index.page].tasks[index.task].hints.push(actionValue);
66-
}
67-
break;
6860
default:
6961
console.log('Invalid task action');
7062
}

src/build/parser/brackets.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/build/parser/cleanup.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ function trimLineBreaks(text) {
88
exports.trimLineBreaks = trimLineBreaks;
99
var quotes = ['\'', '"', '`'];
1010
function trimQuotes(text) {
11-
if (!!text.match(/^\s/)) {
11+
if (!!text.match(/^[\r\n]/)) {
12+
return text;
13+
}
14+
else if (!!text.match(/^\s/)) {
1215
return trimQuotes(text.slice(1));
1316
}
14-
else if (!!text.match(/\s$/m)) {
17+
else if (!!text.match(/\s$/)) {
1518
return trimQuotes(text.slice(0, text.length - 1));
1619
}
1720
else if (!!text.match(/^`{3}.+`{3}$/m)) {

src/build/parser/match.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ exports.isArray = function (line) {
3838
exports.isAction = function (line) {
3939
var match = line.match(/^@(action|test|hint)/);
4040
return !!match ? {
41-
action: match[1],
42-
content: match[2]
41+
action: match[1]
4342
} : false;
4443
};
4544
exports.isImport = function (line) {

src/build/parser/task.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ function task(result, lines, index) {
2828
}
2929
else {
3030
if (!!currentAction) {
31-
var finishedAction = (bracketTracker(line) + bracketCount) === 0;
32-
if (!finishedAction) {
31+
if (line.length === 0) {
32+
currentAction += '\n';
33+
}
34+
else if ((bracketTracker(line) + bracketCount) !== 0) {
3335
currentAction += line + '\n';
3436
bracketCount += bracketTracker(line);
3537
}

0 commit comments

Comments
 (0)