diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-04-05 20:06:38 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-04-05 20:06:38 -0700 |
commit | 4547ec73fda25f037bda2692dc9fc66a037cbde9 (patch) | |
tree | 85e7b33a023efc41d2a4b3acfe44ad168e2e204e /lib/parse/page.js | |
parent | 761cfb4a2c68cfcfa5557dd41ca912cb716df05b (diff) | |
parent | cae62676653e9664fd876a37b6363aecd7cfaf5a (diff) | |
download | gitbook-4547ec73fda25f037bda2692dc9fc66a037cbde9.zip gitbook-4547ec73fda25f037bda2692dc9fc66a037cbde9.tar.gz gitbook-4547ec73fda25f037bda2692dc9fc66a037cbde9.tar.bz2 |
Merge pull request #31 from GitbookIO/feature/lang
Feature/lang
Diffstat (limited to 'lib/parse/page.js')
-rw-r--r-- | lib/parse/page.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/parse/page.js b/lib/parse/page.js index 937d84e..75eca9d 100644 --- a/lib/parse/page.js +++ b/lib/parse/page.js @@ -4,6 +4,9 @@ var hljs = require('highlight.js'); var renderer = require('./renderer'); +var lnormalize = require('../utils/lang').normalize; + + // Synchronous highlighting with highlight.js marked.setOptions({ highlight: function (code, lang) { @@ -100,10 +103,22 @@ function parsePage(src, options) { 'type': 'code' }); + // Languages in code blocks + var langs = _.pluck(codeNodes, 'lang').map(lnormalize); + + // Check that they are all the same + var validLangs = _.all(_.map(langs, function(lang) { + return lang && lang === langs[0]; + })); + + // Main language + var lang = validLangs ? langs[0] : null; + return { id: id, type: section.type, content: render(nonCodeNodes), + lang: lang, code: { base: codeNodes[0].text, solution: codeNodes[1].text, |