Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
egor-rogov committed Oct 16, 2018
1 parent 52ad15c commit 72d2ba6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ https://highlightjs.org/
}

function autoDetection(name) {
name = (name || '').toLowerCase();
return !languages[name].disableAutodetect;
lang = getLanguage(name);
return lang && !lang.disableAutodetect;
}

/* Interface definition */
Expand Down
36 changes: 36 additions & 0 deletions test/api/autoDetection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

let hljs = require('../../build');
let should = require('should');

describe('.autoDetection()', function() {
it('should get an existing language', function() {
const result = hljs.autoDetection('python');

result.should.be.instanceOf(Object);
});

it('should get an existing language by alias', function() {
const result = hljs.autoDetection('py');

result.should.be.instanceOf(Object);
});

it('should be case insensitive', function() {
const result = hljs.autoDetection('pYTHOn');

result.should.be.instanceOf(Object);
});

it('should return undefined', function() {
const result = hljs.autoDetection('-impossible-');

should.strictEqual(result, undefined);
});

it('should not break on undefined', function() {
const result = hljs.autoDetection(undefined);

should.strictEqual(result, undefined);
});
});
6 changes: 6 additions & 0 deletions test/api/getLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ describe('.getLanguage()', function() {
result.should.be.instanceOf(Object);
});

it('should get an existing language by alias', function() {
const result = hljs.getLanguage('py');

result.should.be.instanceOf(Object);
});

it('should be case insensitive', function() {
const result = hljs.getLanguage('pYTHOn');

Expand Down
1 change: 1 addition & 0 deletions test/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('hljs', function() {
require('./binaryNumber');
require('./starters');
require('./getLanguage');
require('./autoDetection');
require('./highlight');
require('./fixmarkup');
});

0 comments on commit 72d2ba6

Please sign in to comment.