diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-04-05 20:04:24 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-04-05 20:04:24 -0700 |
commit | 58bee15f376e5e56477d4e083493d9b6213fbc63 (patch) | |
tree | 5442c344acc9e0d60e103b96f7cc2d34e6a46721 | |
parent | 4987beec2ba6d148d1d1e5f356f977a4daab9732 (diff) | |
download | gitbook-58bee15f376e5e56477d4e083493d9b6213fbc63.zip gitbook-58bee15f376e5e56477d4e083493d9b6213fbc63.tar.gz gitbook-58bee15f376e5e56477d4e083493d9b6213fbc63.tar.bz2 |
Add basic code language normalization
-rw-r--r-- | lib/parse/page.js | 5 | ||||
-rw-r--r-- | lib/utils/index.js | 3 | ||||
-rw-r--r-- | lib/utils/lang.js | 16 |
3 files changed, 23 insertions, 1 deletions
diff --git a/lib/parse/page.js b/lib/parse/page.js index cfe1da8..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) { @@ -101,7 +104,7 @@ function parsePage(src, options) { }); // Languages in code blocks - var langs = _.pluck(codeNodes, 'lang'); + var langs = _.pluck(codeNodes, 'lang').map(lnormalize); // Check that they are all the same var validLangs = _.all(_.map(langs, function(lang) { diff --git a/lib/utils/index.js b/lib/utils/index.js new file mode 100644 index 0000000..155e723 --- /dev/null +++ b/lib/utils/index.js @@ -0,0 +1,3 @@ +module.exports = { + lang: require('./lang'), +}; diff --git a/lib/utils/lang.js b/lib/utils/lang.js new file mode 100644 index 0000000..7fd71e1 --- /dev/null +++ b/lib/utils/lang.js @@ -0,0 +1,16 @@ +var MAP = { + 'py': 'python', + 'js': 'javascript', + 'rb': 'ruby', +}; + +function normalize(lang) { + var lower = lang.toLowerCase(); + return MAP[lower] || lower; +} + +// Exports +module.exports = { + normalize: normalize, + MAP: MAP +}; |