|
3 | 3 | return;
|
4 | 4 | }
|
5 | 5 |
|
6 |
| - // The dependencies map is built automatically with gulp |
| 6 | + /** |
| 7 | + * The dependencies map is built automatically with gulp. |
| 8 | + * |
| 9 | + * @type {Object<string, string | string[]>} |
| 10 | + */ |
7 | 11 | var lang_dependencies = /*dependencies_placeholder[*/{
|
8 | 12 | "javascript": "clike",
|
9 | 13 | "actionscript": "javascript",
|
|
200 | 204 |
|
201 | 205 | var script = Prism.util.currentScript();
|
202 | 206 | if (script) {
|
203 |
| - var autoloaderFile = /\bplugins\/autoloader\/prism-autoloader\.(?:min\.)js$/i; |
204 |
| - var prismFile = /[\w-]+\.(?:min\.)js$/i; |
205 |
| - if (script.hasAttribute('data-autoloader-path')) { |
| 207 | + var autoloaderFile = /\bplugins\/autoloader\/prism-autoloader\.(?:min\.)js(?:\?[^\r\n/]*)?$/i; |
| 208 | + var prismFile = /(^|\/)[\w-]+\.(?:min\.)js(?:\?[^\r\n/]*)?$/i; |
| 209 | + |
| 210 | + var autoloaderPath = script.getAttribute('data-autoloader-path'); |
| 211 | + if (autoloaderPath != null) { |
206 | 212 | // data-autoloader-path is set, so just use it
|
207 |
| - languages_path = script.getAttribute('data-autoloader-path').trim().replace(/\/?$/, '/'); |
| 213 | + languages_path = autoloaderPath.trim().replace(/\/?$/, '/'); |
208 | 214 | } else {
|
209 | 215 | var src = script.src;
|
210 | 216 | if (autoloaderFile.test(src)) {
|
211 | 217 | // the script is the original autoloader script in the usual Prism project structure
|
212 | 218 | languages_path = src.replace(autoloaderFile, 'components/');
|
213 | 219 | } else if (prismFile.test(src)) {
|
214 | 220 | // the script is part of a bundle like a custom prism.js from the download page
|
215 |
| - languages_path = src.replace(prismFile, 'components/'); |
| 221 | + languages_path = src.replace(prismFile, '$1components/'); |
216 | 222 | }
|
217 | 223 | }
|
218 | 224 | }
|
|
270 | 276 | }
|
271 | 277 |
|
272 | 278 | // Look for additional dependencies defined on the <code> or <pre> tags
|
273 |
| - var deps = elt.getAttribute('data-dependencies'); |
274 |
| - var parent = elt.parentElement; |
275 |
| - if (!deps && parent && parent.tagName.toLowerCase() === 'pre') { |
276 |
| - deps = parent.getAttribute('data-dependencies'); |
277 |
| - } |
278 |
| - |
279 |
| - if (deps) { |
280 |
| - deps = deps.split(/\s*,\s*/g); |
281 |
| - } else { |
282 |
| - deps = []; |
| 279 | + var deps = (elt.getAttribute('data-dependencies') || '').trim(); |
| 280 | + if (!deps) { |
| 281 | + var parent = elt.parentElement; |
| 282 | + if (parent && parent.tagName.toLowerCase() === 'pre') { |
| 283 | + deps = (parent.getAttribute('data-dependencies') || '').trim(); |
| 284 | + } |
283 | 285 | }
|
284 | 286 |
|
285 |
| - loadLanguages(deps, function () { |
| 287 | + loadLanguages(deps ? deps.split(/\s*,\s*/g) : [], function () { |
286 | 288 | loadLanguage(lang, function () {
|
287 | 289 | Prism.highlightElement(elt);
|
288 | 290 | });
|
|
0 commit comments