diff --git a/.eslintrc.js b/.eslintrc.js index d9782df5..25525453 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,6 +5,7 @@ module.exports = { rules: { // stylistic rules 'quotes': ['warn', 'single', { avoidEscape: true, allowTemplateLiterals: true }], + 'semi': 'warn', // I turned this rule off because we use `hasOwnProperty` in a lot of places // TODO: Think about re-enabling this rule diff --git a/assets/code.js b/assets/code.js index 70c42b57..23c600ef 100644 --- a/assets/code.js +++ b/assets/code.js @@ -124,7 +124,7 @@ if (toc.children.length > 0) { if (PrefixFree.functions.indexOf('calc') == -1) { var style = document.createElement('_').style; - style.width = 'calc(1px + 1%)' + style.width = 'calc(1px + 1%)'; if(!style.width) { // calc not supported diff --git a/assets/download.js b/assets/download.js index a7bbd875..2b4f2c19 100644 --- a/assets/download.js +++ b/assets/download.js @@ -62,7 +62,7 @@ if (hstr) { if (components[category][id]) { if (components[category][id].option !== 'default') { if (typeof components[category][id] === 'string') { - components[category][id] = { title: components[category][id] } + components[category][id] = { title: components[category][id] }; } components[category][id].option = 'default'; } diff --git a/assets/examples.js b/assets/examples.js index 4ce38bca..ff9f6a59 100644 --- a/assets/examples.js +++ b/assets/examples.js @@ -160,7 +160,7 @@ function buildContentsHeader(id) { header += ':'; header += ''; } diff --git a/components/prism-cil.js b/components/prism-cil.js index e2b4934f..f0f5963f 100644 --- a/components/prism-cil.js +++ b/components/prism-cil.js @@ -24,4 +24,4 @@ Prism.languages.cil = { 'number': /\b-?(?:0x[0-9a-fA-F]+|[0-9]+)(?:\.[0-9a-fA-F]+)?\b/i, 'punctuation': /[{}[\];(),:=]|IL_[0-9A-Za-z]+/ -} +}; diff --git a/components/prism-cpp.js b/components/prism-cpp.js index b771da11..17752781 100644 --- a/components/prism-cpp.js +++ b/components/prism-cpp.js @@ -1,7 +1,7 @@ (function (Prism) { var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/; - var modName = /\b(?!)\w+(?:\s*\.\s*\w+)*\b/.source.replace(//g, function () { return keyword.source; }) + var modName = /\b(?!)\w+(?:\s*\.\s*\w+)*\b/.source.replace(//g, function () { return keyword.source; }); Prism.languages.cpp = Prism.languages.extend('c', { 'class-name': [ diff --git a/components/prism-csharp.js b/components/prism-csharp.js index 35201287..671e2bea 100644 --- a/components/prism-csharp.js +++ b/components/prism-csharp.js @@ -69,7 +69,7 @@ var identifier = replace(/(?!<<0>>)<<1>>(?:\s*\.\s*<<1>>)*/.source, [nonTypeKeywords, genericName]); var array = /\[\s*(?:,\s*)*\]/.source; var typeExpressionWithoutTuple = replace(/<<0>>(?:\s*(?:\?\s*)?<<1>>)*(?:\s*\?)?/.source, [identifier, array]); - var tupleElement = replace(/[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [generic, nestedRound, array]) + var tupleElement = replace(/[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [generic, nestedRound, array]); var tuple = replace(/\(<<0>>+(?:,<<0>>+)+\)/.source, [tupleElement]); var typeExpression = replace(/(?:<<0>>|<<1>>)(?:\s*(?:\?\s*)?<<2>>)*(?:\s*\?)?/.source, [tuple, identifier, array]); @@ -308,10 +308,10 @@ // string interpolation var formatString = /:[^}\r\n]+/.source; // multi line - var mInterpolationRound = nested(replace(/[^"'/()]|<<0>>|\(<>*\)/.source, [regularStringCharacterOrComment]), 2) + var mInterpolationRound = nested(replace(/[^"'/()]|<<0>>|\(<>*\)/.source, [regularStringCharacterOrComment]), 2); var mInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [mInterpolationRound, formatString]); // single line - var sInterpolationRound = nested(replace(/[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<>*\)/.source, [regularStringOrCharacter]), 2) + var sInterpolationRound = nested(replace(/[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<>*\)/.source, [regularStringOrCharacter]), 2); var sInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [sInterpolationRound, formatString]); function createInterpolationInside(interpolation, interpolationRound) { diff --git a/components/prism-dns-zone-file.js b/components/prism-dns-zone-file.js index e2518ca3..7829ac2e 100644 --- a/components/prism-dns-zone-file.js +++ b/components/prism-dns-zone-file.js @@ -30,4 +30,4 @@ Prism.languages['dns-zone-file'] = { 'punctuation': /[()]/ }; -Prism.languages['dns-zone'] = Prism.languages['dns-zone-file'] +Prism.languages['dns-zone'] = Prism.languages['dns-zone-file']; diff --git a/components/prism-haml.js b/components/prism-haml.js index 4ec10b83..eda53ca2 100644 --- a/components/prism-haml.js +++ b/components/prism-haml.js @@ -133,7 +133,7 @@ }, rest: Prism.languages[filter.language] } - } + }; } } diff --git a/components/prism-icu-message-format.js b/components/prism-icu-message-format.js index c5dfeb8a..7b9de169 100644 --- a/components/prism-icu-message-format.js +++ b/components/prism-icu-message-format.js @@ -12,7 +12,7 @@ if (level <= 0) { return /[]/.source; } else { - return source.replace(//g, function () { return nested(source, level - 1) }); + return source.replace(//g, function () { return nested(source, level - 1); }); } } diff --git a/components/prism-ignore.js b/components/prism-ignore.js index 597516be..b81ac28d 100644 --- a/components/prism-ignore.js +++ b/components/prism-ignore.js @@ -16,8 +16,8 @@ } }; - Prism.languages.gitignore = Prism.languages.ignore - Prism.languages.hgignore = Prism.languages.ignore - Prism.languages.npmignore = Prism.languages.ignore + Prism.languages.gitignore = Prism.languages.ignore; + Prism.languages.hgignore = Prism.languages.ignore; + Prism.languages.npmignore = Prism.languages.ignore; }(Prism)); diff --git a/components/prism-javadoc.js b/components/prism-javadoc.js index c0c3151a..6e0219e3 100644 --- a/components/prism-javadoc.js +++ b/components/prism-javadoc.js @@ -3,7 +3,7 @@ var codeLinePattern = /(^(?:\s*(?:\*\s*)*))[^*\s].*$/m; var memberReference = /#\s*\w+(?:\s*\([^()]*\))?/.source; - var reference = /(?:[a-zA-Z]\w+\s*\.\s*)*[A-Z]\w*(?:\s*)?|/.source.replace(//g, function () { return memberReference }); + var reference = /(?:[a-zA-Z]\w+\s*\.\s*)*[A-Z]\w*(?:\s*)?|/.source.replace(//g, function () { return memberReference; }); Prism.languages.javadoc = Prism.languages.extend('javadoclike', {}); Prism.languages.insertBefore('javadoc', 'keyword', { diff --git a/components/prism-jq.js b/components/prism-jq.js index ee44b3a0..a1dd4355 100644 --- a/components/prism-jq.js +++ b/components/prism-jq.js @@ -60,7 +60,7 @@ pattern: /\./, alias: 'important' } - } + }; stringInterpolation.interpolation.inside.content.inside = jq; diff --git a/components/prism-json5.js b/components/prism-json5.js index 855e6d54..c8cccad9 100644 --- a/components/prism-json5.js +++ b/components/prism-json5.js @@ -1,6 +1,6 @@ (function (Prism) { - var string = /("|')(?:\\(?:\r\n?|\n|.)|(?!\1)[^\\\r\n])*\1/ + var string = /("|')(?:\\(?:\r\n?|\n|.)|(?!\1)[^\\\r\n])*\1/; Prism.languages.json5 = Prism.languages.extend('json', { 'property': [ diff --git a/components/prism-jsstacktrace.js b/components/prism-jsstacktrace.js index cab1224b..479903a5 100644 --- a/components/prism-jsstacktrace.js +++ b/components/prism-jsstacktrace.js @@ -45,4 +45,4 @@ Prism.languages.jsstacktrace = { } } -} +}; diff --git a/components/prism-jsx.js b/components/prism-jsx.js index 434e695a..b1adb391 100644 --- a/components/prism-jsx.js +++ b/components/prism-jsx.js @@ -105,7 +105,7 @@ var walkTokens = function (tokens) { openedTags[openedTags.length - 1].openedBraces--; } else { - notTagNorBrace = true + notTagNorBrace = true; } } if (notTagNorBrace || typeof token === 'string') { diff --git a/components/prism-markdown.js b/components/prism-markdown.js index 5c2ca6f9..715b1ff3 100644 --- a/components/prism-markdown.js +++ b/components/prism-markdown.js @@ -297,7 +297,7 @@ // this might be a language that Prism does not support // do some replacements to support C++, C#, and F# - var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp') + var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp'); // only use the first word lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase(); var alias = 'language-' + lang; diff --git a/components/prism-nevod.js b/components/prism-nevod.js index 6a8d216f..398238be 100644 --- a/components/prism-nevod.js +++ b/components/prism-nevod.js @@ -122,4 +122,4 @@ Prism.languages.nevod = { ], 'punctuation': /[:;,()]/, 'name': /[a-zA-Z0-9\-.]+/ -} +}; diff --git a/components/prism-powerquery.js b/components/prism-powerquery.js index 7abf0ad5..fb21d849 100644 --- a/components/prism-powerquery.js +++ b/components/prism-powerquery.js @@ -52,4 +52,4 @@ Prism.languages.powerquery = { }; Prism.languages.pq = Prism.languages['powerquery']; -Prism.languages.mscript = Prism.languages['powerquery'] \ No newline at end of file +Prism.languages.mscript = Prism.languages['powerquery']; \ No newline at end of file diff --git a/components/prism-pug.js b/components/prism-pug.js index 49877db5..78ccd292 100644 --- a/components/prism-pug.js +++ b/components/prism-pug.js @@ -174,7 +174,7 @@ }, rest: Prism.languages[filter.language] } - } + }; } } diff --git a/components/prism-qsharp.js b/components/prism-qsharp.js index 25198db3..2e97ade8 100644 --- a/components/prism-qsharp.js +++ b/components/prism-qsharp.js @@ -46,7 +46,7 @@ type: 'Adj BigInt Bool Ctl Double false Int One Pauli PauliI PauliX PauliY PauliZ Qubit Range Result String true Unit Zero', // all other keywords other: 'Adjoint adjoint apply as auto body borrow borrowing Controlled controlled distribute elif else fail fixup for function if in internal intrinsic invert is let mutable namespace new newtype open operation repeat return self set until use using while within' - } + }; // keywords function keywordsToPattern(words) { return '\\b(?:' + words.trim().replace(/ /g, '|') + ')\\b'; diff --git a/components/prism-regex.js b/components/prism-regex.js index 6d7c301d..ca4a4534 100644 --- a/components/prism-regex.js +++ b/components/prism-regex.js @@ -101,4 +101,4 @@ } }; -}(Prism)) +}(Prism)); diff --git a/components/prism-splunk-spl.js b/components/prism-splunk-spl.js index b9ec3fc8..47dbcdf2 100644 --- a/components/prism-splunk-spl.js +++ b/components/prism-splunk-spl.js @@ -21,4 +21,4 @@ Prism.languages['splunk-spl'] = { 'boolean': /\b(?:f|false|t|true)\b/i, 'operator': /[<>=]=?|[-+*/%|]/, 'punctuation': /[()[\],]/ -} +}; diff --git a/components/prism-xquery.js b/components/prism-xquery.js index 8541263b..5a4a9ba6 100644 --- a/components/prism-xquery.js +++ b/components/prism-xquery.js @@ -118,7 +118,7 @@ openedTags[openedTags.length - 1].openedBraces--; } else if (token.type !== 'comment') { - notTagNorBrace = true + notTagNorBrace = true; } } if (notTagNorBrace || typeof token === 'string') { diff --git a/components/prism-yaml.js b/components/prism-yaml.js index fe0a5b99..2cecda8a 100644 --- a/components/prism-yaml.js +++ b/components/prism-yaml.js @@ -25,7 +25,7 @@ flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag var pattern = /([:\-,[{]\s*(?:\s<>[ \t]+)?)(?:<>)(?=[ \t]*(?:$|,|]|}|(?:[\r\n]\s*)?#))/.source .replace(/<>/g, function () { return properties; }).replace(/<>/g, function () { return value; }); - return RegExp(pattern, flags) + return RegExp(pattern, flags); } Prism.languages.yaml = { diff --git a/dangerfile.js b/dangerfile.js index 76f4d155..36face95 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -54,7 +54,7 @@ const formatBytes = (bytes, decimals = 2) => { const i = Math.floor(Math.log(Math.abs(bytes)) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; -} +}; const maybePlus = (from, to) => from < to ? '+' : ''; @@ -64,7 +64,7 @@ const absDiff = (from, to) => { } return `${maybePlus(from, to)}${formatBytes(to - from)}`; -} +}; const percDiff = (from, to) => { if (from === to) { @@ -72,7 +72,7 @@ const percDiff = (from, to) => { } return `${maybePlus(from, to)}${(100 * (to - from) / (from || to)).toFixed(1)}%`; -} +}; const getSummary = (rows, totalMasterFileSize, totalFileSize) => { const numFiles = rows.length; @@ -81,7 +81,7 @@ const getSummary = (rows, totalMasterFileSize, totalFileSize) => { const percentDiff = percDiff(totalMasterFileSize, totalFileSize); return `A total of ${numFiles} file${maybeS} have changed, with a combined diff of ${byteDiff} (${percentDiff}).`; -} +}; const run = async () => { const minified = await getChangedMinifiedFiles(); @@ -107,7 +107,7 @@ const run = async () => { ]); totalFileSize += fileSize; - totalMasterFileSize += fileMasterSize + totalMasterFileSize += fileMasterSize; rows.push([ file, @@ -130,7 +130,7 @@ ${rows.map(row => `| ${row.join(' | ')} |`).join('\n')} `); -} +}; run().catch(err => { console.error(err); diff --git a/gulpfile.js/changelog.js b/gulpfile.js/changelog.js index 984dc675..899a3d75 100644 --- a/gulpfile.js/changelog.js +++ b/gulpfile.js/changelog.js @@ -369,7 +369,7 @@ async function changes() { for (const subCategory of Object.keys(category).sort(strCompare)) { if (subCategory) { md += `${indentation}* __${subCategory}__\n`; - printCategory(category[subCategory], indentation + ' ') + printCategory(category[subCategory], indentation + ' '); } else { for (const info of category['']) { md += `${indentation}* ${infoToString(info)}\n`; diff --git a/gulpfile.js/docs.js b/gulpfile.js/docs.js index 1e5b1c88..0dcf9199 100644 --- a/gulpfile.js/docs.js +++ b/gulpfile.js/docs.js @@ -65,7 +65,7 @@ module.exports = { // error if used. So we just replace the "function" with some literal that JSDoc will interpret as a // namespace. Not pretty but it works. comment.comment = comment.comment - .replace(/\bimport\s*\(\s*(?:"(?:[^"\r\n\\]|\\.)*"|'(?:[^'\r\n\\]|\\.)*')\s*\)/g, '__dyn_import__') + .replace(/\bimport\s*\(\s*(?:"(?:[^"\r\n\\]|\\.)*"|'(?:[^'\r\n\\]|\\.)*')\s*\)/g, '__dyn_import__'); } } }; diff --git a/plugins/autoloader/prism-autoloader.js b/plugins/autoloader/prism-autoloader.js index 2da746f8..035e47f1 100644 --- a/plugins/autoloader/prism-autoloader.js +++ b/plugins/autoloader/prism-autoloader.js @@ -354,7 +354,7 @@ * @returns {string} */ function getLanguagePath(lang) { - return config.languages_path + 'prism-' + lang + (config.use_minified ? '.min' : '') + '.js' + return config.languages_path + 'prism-' + lang + (config.use_minified ? '.min' : '') + '.js'; } /** diff --git a/plugins/copy-to-clipboard/prism-copy-to-clipboard.js b/plugins/copy-to-clipboard/prism-copy-to-clipboard.js index 04d69c8b..4721a2f4 100644 --- a/plugins/copy-to-clipboard/prism-copy-to-clipboard.js +++ b/plugins/copy-to-clipboard/prism-copy-to-clipboard.js @@ -79,7 +79,7 @@ */ function selectElementText(element) { // https://stackoverflow.com/a/20079910/7595472 - window.getSelection().selectAllChildren(element) + window.getSelection().selectAllChildren(element); } /** diff --git a/plugins/custom-class/prism-custom-class.js b/plugins/custom-class/prism-custom-class.js index c2c6622a..44b4ccf9 100644 --- a/plugins/custom-class/prism-custom-class.js +++ b/plugins/custom-class/prism-custom-class.js @@ -63,7 +63,7 @@ prefix: function prefix(string) { prefixString = string || ''; } - } + }; Prism.hooks.add('wrap', function (env) { if (adder) { diff --git a/plugins/file-highlight/prism-file-highlight.js b/plugins/file-highlight/prism-file-highlight.js index 79893a83..78c0def8 100644 --- a/plugins/file-highlight/prism-file-highlight.js +++ b/plugins/file-highlight/prism-file-highlight.js @@ -140,6 +140,6 @@ logged = true; } Prism.plugins.fileHighlight.highlight.apply(this, arguments); - } + }; })(); diff --git a/plugins/line-highlight/prism-line-highlight.js b/plugins/line-highlight/prism-line-highlight.js index 1735e7ca..652bfeb0 100644 --- a/plugins/line-highlight/prism-line-highlight.js +++ b/plugins/line-highlight/prism-line-highlight.js @@ -56,7 +56,7 @@ document.body.removeChild(d); } return res; - } + }; }()); /** diff --git a/plugins/normalize-whitespace/prism-normalize-whitespace.js b/plugins/normalize-whitespace/prism-normalize-whitespace.js index 13683fed..5735d98f 100644 --- a/plugins/normalize-whitespace/prism-normalize-whitespace.js +++ b/plugins/normalize-whitespace/prism-normalize-whitespace.js @@ -10,7 +10,7 @@ var assign = Object.assign || function (obj1, obj2) { obj1[name] = obj2[name]; } return obj1; -} +}; function NormalizeWhitespace(defaults) { this.defaults = assign({}, defaults); diff --git a/plugins/wpd/prism-wpd.js b/plugins/wpd/prism-wpd.js index b6123969..140e18c5 100644 --- a/plugins/wpd/prism-wpd.js +++ b/plugins/wpd/prism-wpd.js @@ -44,7 +44,7 @@ if (Prism.languages.markup) { 'hkern': 1, 'vkern': 1 }, MathML: {} - } + }; } var language; diff --git a/prism.js b/prism.js index 5982d5ca..d5ff4efc 100644 --- a/prism.js +++ b/prism.js @@ -1769,6 +1769,6 @@ Prism.languages.js = Prism.languages.javascript; logged = true; } Prism.plugins.fileHighlight.highlight.apply(this, arguments); - } + }; })(); diff --git a/tests/dependencies-test.js b/tests/dependencies-test.js index 7988f11d..ebacf5bf 100644 --- a/tests/dependencies-test.js +++ b/tests/dependencies-test.js @@ -318,12 +318,12 @@ describe('components.json', function () { for (const modifyId of toArray(entry.modify)) { if (optional.has(modifyId)) { - assert.fail(`The component "${id}" has declared "${modifyId}" as both optional and modify.`) + assert.fail(`The component "${id}" has declared "${modifyId}" as both optional and modify.`); } } for (const requireId of toArray(entry.require)) { if (optional.has(requireId)) { - assert.fail(`The component "${id}" has declared "${requireId}" as both optional and require.`) + assert.fail(`The component "${id}" has declared "${requireId}" as both optional and require.`); } } }); diff --git a/tests/examples-test.js b/tests/examples-test.js index 0a4f3e41..a993afcb 100644 --- a/tests/examples-test.js +++ b/tests/examples-test.js @@ -151,7 +151,7 @@ function parseHTML(html) { const p = new Parser({ onerror(err) { - reject(err) + reject(err); }, onend() { resolve(tree); diff --git a/tests/helper/checks.js b/tests/helper/checks.js index 69fd17e1..c667537f 100644 --- a/tests/helper/checks.js +++ b/tests/helper/checks.js @@ -110,7 +110,7 @@ module.exports = (Prism) => { } else { elementStr = String(element); } - redefStr += `\t'${key}': ${elementStr},\n` + redefStr += `\t'${key}': ${elementStr},\n`; } redefStr += '}'; } else { diff --git a/tests/helper/test-case.js b/tests/helper/test-case.js index 184d6c14..4879af10 100644 --- a/tests/helper/test-case.js +++ b/tests/helper/test-case.js @@ -74,7 +74,7 @@ module.exports = { if (testCase.comment.trim()) { content += separator + testCase.comment.trim(); } - content += '\n' + content += '\n'; content = content.replace(/\r?\n/g, lineEnd); fs.writeFileSync(filePath, content, 'utf-8'); diff --git a/tests/helper/token-stream-transformer.js b/tests/helper/token-stream-transformer.js index c405b6ed..a704bf5d 100644 --- a/tests/helper/token-stream-transformer.js +++ b/tests/helper/token-stream-transformer.js @@ -286,8 +286,8 @@ function printPrettyTokenStream(prettyStream, indentationLevel = 1, indentationC const lineEnd = (i === prettyStream.length - 1) ? '\n' : ',\n'; out += lineEnd; } - }) - out += indentation.substr(indentationChar.length) + ']' + }); + out += indentation.substr(indentationChar.length) + ']'; return out; } diff --git a/tests/plugins/keep-markup/test.js b/tests/plugins/keep-markup/test.js index af2f006b..bc98ef02 100644 --- a/tests/plugins/keep-markup/test.js +++ b/tests/plugins/keep-markup/test.js @@ -1,18 +1,18 @@ /* eslint-disable no-undef */ const expect = require('chai').expect; -const jsdom = require('jsdom') -const { JSDOM } = jsdom +const jsdom = require('jsdom'); +const { JSDOM } = jsdom; -require('../../../prism') +require('../../../prism'); // fake DOM -global.self = {} -global.self.Prism = Prism -global.document = {} +global.self = {}; +global.self.Prism = Prism; +global.document = {}; document.createRange = function () { -} -global.self.document = document +}; +global.self.document = document; -require('../../../plugins/keep-markup/prism-keep-markup') +require('../../../plugins/keep-markup/prism-keep-markup'); describe('Prism Keep Markup Plugin', function () { @@ -23,62 +23,62 @@ describe('Prism Keep Markup Plugin', function () { document.createRange = function () { return { setStart: function (node, offset) { - start.push({ node, offset }) + start.push({ node, offset }); }, setEnd: function (node, offset) { - end.push({ node, offset }) + end.push({ node, offset }); }, extractContents: function () { - return new JSDOM('').window.document.createTextNode('') + return new JSDOM('').window.document.createTextNode(''); }, insertNode: function (node) { - nodes.push(node) + nodes.push(node); }, detach: function () { } - } - } - const beforeHighlight = Prism.hooks.all['before-highlight'][0] - const afterHighlight = Prism.hooks.all['after-highlight'][0] + }; + }; + const beforeHighlight = Prism.hooks.all['before-highlight'][0]; + const afterHighlight = Prism.hooks.all['after-highlight'][0]; const env = { element: new JSDOM(code).window.document.getElementsByTagName('code')[0], language: 'javascript' - } - beforeHighlight(env) - afterHighlight(env) - return { start, end, nodes } + }; + beforeHighlight(env); + afterHighlight(env); + return { start, end, nodes }; } it('should keep markup', function () { - const result = execute(`xay`) - expect(result.start.length).to.equal(1) - expect(result.end.length).to.equal(1) - expect(result.nodes.length).to.equal(1) - expect(result.nodes[0].nodeName).to.equal('SPAN') - }) + const result = execute(`xay`); + expect(result.start.length).to.equal(1); + expect(result.end.length).to.equal(1); + expect(result.nodes.length).to.equal(1); + expect(result.nodes[0].nodeName).to.equal('SPAN'); + }); it('should preserve markup order', function () { - const result = execute(`xy`) - expect(result.start.length).to.equal(2) - expect(result.start[0].offset).to.equal(0) - expect(result.start[0].node.textContent).to.equal('y') - expect(result.start[1].offset).to.equal(0) - expect(result.start[1].node.textContent).to.equal('y') - expect(result.end.length).to.equal(2) - expect(result.end[0].offset).to.equal(0) - expect(result.end[0].node.textContent).to.equal('y') - expect(result.end[1].offset).to.equal(0) - expect(result.end[1].node.textContent).to.equal('y') - expect(result.nodes.length).to.equal(2) - expect(result.nodes[0].nodeName).to.equal('A') - expect(result.nodes[1].nodeName).to.equal('B') - }) + const result = execute(`xy`); + expect(result.start.length).to.equal(2); + expect(result.start[0].offset).to.equal(0); + expect(result.start[0].node.textContent).to.equal('y'); + expect(result.start[1].offset).to.equal(0); + expect(result.start[1].node.textContent).to.equal('y'); + expect(result.end.length).to.equal(2); + expect(result.end[0].offset).to.equal(0); + expect(result.end[0].node.textContent).to.equal('y'); + expect(result.end[1].offset).to.equal(0); + expect(result.end[1].node.textContent).to.equal('y'); + expect(result.nodes.length).to.equal(2); + expect(result.nodes[0].nodeName).to.equal('A'); + expect(result.nodes[1].nodeName).to.equal('B'); + }); it('should keep last markup', function () { - const result = execute(`xya`) - expect(result.start.length).to.equal(1) - expect(result.end.length).to.equal(1) - expect(result.nodes.length).to.equal(1) - expect(result.nodes[0].nodeName).to.equal('SPAN') - }) + const result = execute(`xya`); + expect(result.start.length).to.equal(1); + expect(result.end.length).to.equal(1); + expect(result.nodes.length).to.equal(1); + expect(result.nodes[0].nodeName).to.equal('SPAN'); + }); // The markup is removed if it's the last element and the element's name is a single letter: a(nchor), b(old), i(talic)... // https://github.com/PrismJS/prism/issues/1618 /* @@ -90,4 +90,4 @@ describe('Prism Keep Markup Plugin', function () { expect(result.nodes[0].nodeName).to.equal('A') }) */ -}) +});