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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
const { createUtil, createScopedPrismDom } = require('../../helper/prism-dom-util');
describe('Custom class', function () {
const { Prism, window } = createScopedPrismDom(this, {
languages: 'javascript',
plugins: 'custom-class'
});
const util = createUtil(window);
it('should set prefix', function () {
Prism.plugins.customClass.prefix('prism-');
util.assert.highlight({
language: 'javascript',
code: `var a = true;`,
expected: `<span class="prism-token prism-keyword">var</span> a <span class="prism-token prism-operator">=</span> <span class="prism-token prism-boolean">true</span><span class="prism-token prism-punctuation">;</span>`
});
});
it('should reset prefix', function () {
Prism.plugins.customClass.prefix('');
util.assert.highlight({
language: 'javascript',
code: `var a = true;`,
expected: `<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>`
});
});
it('should map class names using a function', function () {
Prism.plugins.customClass.map(function (cls, language) {
return `${language}-${cls}`;
});
util.assert.highlight({
language: 'javascript',
code: `var a = true;`,
expected: `<span class="javascript-token javascript-keyword">var</span> a <span class="javascript-token javascript-operator">=</span> <span class="javascript-token javascript-boolean">true</span><span class="javascript-token javascript-punctuation">;</span>`
});
});
it('should map class names using an object', function () {
Prism.plugins.customClass.map({
boolean: 'b',
keyword: 'kw',
operator: 'op',
punctuation: 'p'
});
util.assert.highlight({
language: 'javascript',
code: `var a = true;`,
expected: `<span class="token kw">var</span> a <span class="token op">=</span> <span class="token b">true</span><span class="token p">;</span>`
});
});
it('should reset map', function () {
Prism.plugins.customClass.map({});
util.assert.highlight({
language: 'javascript',
code: `var a = true;`,
expected: `<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>`
});
});
});