summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@friendco.de>2014-04-05 13:53:31 -0700
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-04-05 13:53:31 -0700
commite414cbd6d1f9b1174123557622e03da9c56aa3dc (patch)
tree33f7476e55cdf2064e0bfacdb9a5504e026823b2
parent959a2d830a634e9c0654cc747f5dd82ea66ef6b1 (diff)
downloadgitbook-e414cbd6d1f9b1174123557622e03da9c56aa3dc.zip
gitbook-e414cbd6d1f9b1174123557622e03da9c56aa3dc.tar.gz
gitbook-e414cbd6d1f9b1174123557622e03da9c56aa3dc.tar.bz2
Detect exercise language
And ensure that all code blocks use the same language
-rw-r--r--lib/parse/page.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/parse/page.js b/lib/parse/page.js
index 937d84e..cfe1da8 100644
--- a/lib/parse/page.js
+++ b/lib/parse/page.js
@@ -100,10 +100,22 @@ function parsePage(src, options) {
'type': 'code'
});
+ // Languages in code blocks
+ var langs = _.pluck(codeNodes, 'lang');
+
+ // 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,