blob: 7a1bf8e475759a8e3e4607b9bdb4be812c277215 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
const GitBook = require('gitbook-core');
const { List } = GitBook.Immutable;
const ALIASES = require('./ALIASES');
/**
* Return language for a code blocks from a list of class names
*
* @param {String} className
* @return {String}
*/
function getLanguage(className) {
const lang = List(className.split(' '))
.map(function(cl) {
// Markdown
if (cl.search('lang-') === 0) {
return cl.slice('lang-'.length);
}
// Asciidoc
if (cl.search('language-') === 0) {
return cl.slice('language-'.length);
}
return null;
})
.find(function(cl) {
return Boolean(cl);
});
return ALIASES[lang] || lang;
}
module.exports = getLanguage;
|