diff options
Diffstat (limited to 'lib/parse')
-rw-r--r-- | lib/parse/index.js | 1 | ||||
-rw-r--r-- | lib/parse/lex.js | 2 | ||||
-rw-r--r-- | lib/parse/page.js | 22 | ||||
-rw-r--r-- | lib/parse/readme.js | 32 |
4 files changed, 44 insertions, 13 deletions
diff --git a/lib/parse/index.js b/lib/parse/index.js index 0e333e4..0ebb03a 100644 --- a/lib/parse/index.js +++ b/lib/parse/index.js @@ -5,4 +5,5 @@ module.exports = { lex: require('./lex'), progress: require('./progress'), navigation: require('./navigation'), + readme: require('./readme') }; diff --git a/lib/parse/lex.js b/lib/parse/lex.js index 813dd33..17eab69 100644 --- a/lib/parse/lex.js +++ b/lib/parse/lex.js @@ -56,7 +56,7 @@ function isQuiz(nodes) { if( // List of questions - listIdx !== -1 && isQuizNode(quizNodes[listIdx + 1]) && + listIdx !== -1 && isQuizNode(quizNodes[listIdx + 1]) || // Table of questions ( diff --git a/lib/parse/page.js b/lib/parse/page.js index eb118e4..efadf82 100644 --- a/lib/parse/page.js +++ b/lib/parse/page.js @@ -8,17 +8,6 @@ var renderer = require('./renderer'); var lnormalize = require('../utils/lang').normalize; -// Synchronous highlighting with highlight.js -marked.setOptions({ - highlight: function (code, lang) { - try { - return hljs.highlight(lang, code).value; - } catch(e) { - return hljs.highlightAuto(code).value; - } - } -}); - // Render a section using our custom renderer function render(section, _options) { @@ -30,7 +19,16 @@ function render(section, _options) { // Build options using defaults and our custom renderer var options = _.extend({}, marked.defaults, { - renderer: renderer(null, _options) + renderer: renderer(null, _options), + + // Synchronous highlighting with highlight.js + highlight: function (code, lang) { + try { + return hljs.highlight(lang, code).value; + } catch(e) { + return hljs.highlightAuto(code).value; + } + } }); return marked.parser(section, options); diff --git a/lib/parse/readme.js b/lib/parse/readme.js new file mode 100644 index 0000000..aab094d --- /dev/null +++ b/lib/parse/readme.js @@ -0,0 +1,32 @@ +var _ = require('lodash'); +var marked = require('marked'); + +function extractFirstNode(nodes, nType) { + return _.chain(nodes) + .filter(function(node) { + return node.type == nType; + }) + .pluck("text") + .first() + .value(); +} + + +function parseReadme(src) { + var nodes, title, description; + + // Parse content + nodes = marked.lexer(src); + + var title = extractFirstNode(nodes, "heading"); + var description = extractFirstNode(nodes, "paragraph"); + + return { + title: title, + description: description + }; +} + + +// Exports +module.exports = parseReadme; |