Skip to content

Commit

Permalink
Allow empty string to supress prefix
Browse files Browse the repository at this point in the history
Closes GH-4.
  • Loading branch information
wooorm committed Sep 17, 2016
1 parent f7b5247 commit 6d9bab7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var own = {}.hasOwnProperty;
*/
function autoHighlight(value, options) {
var settings = options || {};
var prefix = settings.prefix || DEFAULT_PREFIX;
var prefix = settings.prefix;
var subset = settings.subset || languageNames;
var length = subset.length;
var index = -1;
Expand All @@ -87,6 +87,10 @@ function autoHighlight(value, options) {
var current;
var name;

if (prefix === null || prefix === undefined) {
prefix = DEFAULT_PREFIX;
}

if (typeof value !== 'string') {
throw new Error('Expected `string` for value, got `' + value + '`');
}
Expand Down Expand Up @@ -134,7 +138,11 @@ function autoHighlight(value, options) {
*/
function highlight(language, value, options) {
var settings = options || {};
var prefix = settings.prefix || DEFAULT_PREFIX;
var prefix = settings.prefix;

if (prefix === null || prefix === undefined) {
prefix = DEFAULT_PREFIX;
}

return normalize(coreHighlight(language, value, true, prefix));
}
Expand Down
26 changes: 26 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ test('lowlight.highlight(language, value[, options])', function (t) {
st.end();
});

t.test('empty `prefix`', function (st) {
var result = low.highlight('js', '"use strict";', {
prefix: ''
});

t.deepEqual(
result.value[0].properties.className,
['meta'],
'should support an empty `prefix`'
);

st.end();
});

t.end();
});

Expand Down Expand Up @@ -269,6 +283,18 @@ test('lowlight(value[, options])', function (t) {
st.end();
});

t.test('empty `prefix`', function (st) {
var result = low.highlightAuto('"use strict";', {prefix: ''});

t.deepEqual(
result.value[0].properties.className,
['meta'],
'should support an empty `prefix`'
);

st.end();
});

t.test('custom `subset`', function (st) {
var result = low.highlightAuto('"use strict";', {subset: ['java']});

Expand Down

0 comments on commit 6d9bab7

Please sign in to comment.