diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-04-08 15:01:12 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-04-08 15:01:12 -0700 |
commit | 392573a9905a36d4a6c3cc1947c533f742b653a2 (patch) | |
tree | dd47c5039cdf2b24e8b54c141d2d5f161d116f4b | |
parent | 554d6a6170d448d3c4cd635528d4f94e928472f2 (diff) | |
download | gitbook-392573a9905a36d4a6c3cc1947c533f742b653a2.zip gitbook-392573a9905a36d4a6c3cc1947c533f742b653a2.tar.gz gitbook-392573a9905a36d4a6c3cc1947c533f742b653a2.tar.bz2 |
Add lexing support for content code in exercises
#52, #49, #46
-rw-r--r-- | lib/parse/lex.js | 5 | ||||
-rw-r--r-- | lib/parse/page.js | 2 | ||||
-rw-r--r-- | test/fixtures/PAGE.md | 33 | ||||
-rw-r--r-- | test/page.js | 10 |
4 files changed, 48 insertions, 2 deletions
diff --git a/lib/parse/lex.js b/lib/parse/lex.js index 6b3236e..def74b4 100644 --- a/lib/parse/lex.js +++ b/lib/parse/lex.js @@ -23,7 +23,10 @@ function sectionType(nodes, idx) { type: 'code' }).length; - if(codeNodes === 3 && (idx % 2) == 1) { + if( + (codeNodes === 3 || codeNodes === 4) && + (idx % 2) === 1) + { return 'exercise'; } diff --git a/lib/parse/page.js b/lib/parse/page.js index 56a9e60..3479c85 100644 --- a/lib/parse/page.js +++ b/lib/parse/page.js @@ -72,6 +72,8 @@ function parsePage(src, options) { base: codeNodes[0].text, solution: codeNodes[1].text, validation: codeNodes[2].text, + // Context is optional + context: codeNodes[3] ? codeNodes[3].text : null, } }; } diff --git a/test/fixtures/PAGE.md b/test/fixtures/PAGE.md index 2839e6d..92ee707 100644 --- a/test/fixtures/PAGE.md +++ b/test/fixtures/PAGE.md @@ -30,3 +30,36 @@ Some more nice content .... [Cool stuff](http://gitbook.io) [Link to another Markdown file](./xyz/file.md) + +Lets go for another exercise but this time with some context : + +--- + +Exercise with some context code : + +Using the `double` function provided, build a `quadruple` function + +```py + +``` + +```py + +def quadruple(x): + return double(double(x)) + +``` + +```py +assert(quadruple(8), 32) +``` + +```py + +def double(x): + return x * 2 + +``` + +--- + diff --git a/test/page.js b/test/page.js index 0f54809..658559e 100644 --- a/test/page.js +++ b/test/page.js @@ -16,7 +16,7 @@ var LINKS_CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/GITHUB_LINK describe('Page parsing', function() { it('should detection sections', function() { - assert.equal(LEXED.length, 3); + assert.equal(LEXED.length, 4); }); it('should detection section types', function() { @@ -36,6 +36,14 @@ describe('Page parsing', function() { assert(LEXED[1].code.base); assert(LEXED[1].code.solution); assert(LEXED[1].code.validation); + assert(LEXED[1].code.context === null); + + assert(LEXED[3].content); + assert(LEXED[3].code); + assert(LEXED[3].code.base); + assert(LEXED[3].code.solution); + assert(LEXED[3].code.validation); + assert(LEXED[3].code.context); }); it('should merge sections correctly', function() { |