Skip to content

Commit c50d391

Browse files
committed
handle codeblock languages in build
1 parent 3537be5 commit c50d391

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

cli.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#! /usr/bin/env node
2-
32
"use strict";
43
var program = require('commander');
54
var chalk = require('chalk');
@@ -10,7 +9,7 @@ var tutorials_1 = require('./src/tutorials/tutorials');
109
var publish_1 = require('./src/publish/publish');
1110
var docs_1 = require('./src/docs/docs');
1211
program
13-
.version('0.3.9')
12+
.version('0.3.10')
1413
.usage('[options] <keywords>')
1514
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
1615
.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.9",
3+
"version": "0.3.10",
44
"description": "Command line interface for CodeRoad. Build project files.",
55
"keywords": [
66
"coderoad"

src/build/parser/page.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function page(result, lines, index) {
2121
}
2222
else {
2323
if (!!Match.codeBlock(line)) {
24+
if (line.length > 3) {
25+
result = addToDescriptionOrExplanation(hasBreak, i, result, line, index);
26+
continue;
27+
}
2428
inCodeBlock = !inCodeBlock;
2529
}
2630
if (!inCodeBlock) {
@@ -40,28 +44,32 @@ function page(result, lines, index) {
4044
return task_1.task(result, lines.slice(i), index);
4145
}
4246
else {
43-
if (!hasBreak) {
44-
if (result.chapters[index.chapter].pages[index.page].description === undefined) {
45-
result.chapters[index.chapter].pages[index.page].description = '';
46-
}
47-
if (i > 1) {
48-
result.chapters[index.chapter].pages[index.page].description += '\n';
49-
}
50-
result.chapters[index.chapter].pages[index.page].description += line;
51-
}
52-
else {
53-
if (result.chapters[index.chapter].pages[index.page].explanation === undefined) {
54-
result.chapters[index.chapter].pages[index.page].explanation = '';
55-
}
56-
if (i > 3) {
57-
result.chapters[index.chapter].pages[index.page].explanation += '\n';
58-
}
59-
result.chapters[index.chapter].pages[index.page].explanation += line;
60-
}
47+
result = addToDescriptionOrExplanation(hasBreak, i, result, line, index);
6148
}
6249
}
6350
}
6451
}
6552
return result;
6653
}
6754
exports.page = page;
55+
function addToDescriptionOrExplanation(hasBreak, i, result, line, index) {
56+
if (!hasBreak) {
57+
if (result.chapters[index.chapter].pages[index.page].description === undefined) {
58+
result.chapters[index.chapter].pages[index.page].description = '';
59+
}
60+
if (i > 1) {
61+
result.chapters[index.chapter].pages[index.page].description += '\n';
62+
}
63+
result.chapters[index.chapter].pages[index.page].description += line;
64+
}
65+
else {
66+
if (result.chapters[index.chapter].pages[index.page].explanation === undefined) {
67+
result.chapters[index.chapter].pages[index.page].explanation = '';
68+
}
69+
if (i > 3) {
70+
result.chapters[index.chapter].pages[index.page].explanation += '\n';
71+
}
72+
result.chapters[index.chapter].pages[index.page].explanation += line;
73+
}
74+
return result;
75+
}

0 commit comments

Comments
 (0)