mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 02:23:30 +00:00
Add basic code language normalization
This commit is contained in:
+4
-1
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
lang: require('./lang'),
|
||||
};
|
||||
@@ -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
|
||||
};
|
||||
Reference in New Issue
Block a user