1 | (function () {
|
2 |
|
3 | if (typeof Prism === 'undefined' || typeof document === 'undefined' || !document.querySelector) {
|
4 | return;
|
5 | }
|
6 |
|
7 | Prism.plugins.toolbar.registerButton('download-file', function (env) {
|
8 | var pre = env.element.parentNode;
|
9 | if (!pre || !/pre/i.test(pre.nodeName) || !pre.hasAttribute('data-src') || !pre.hasAttribute('data-download-link')) {
|
10 | return;
|
11 | }
|
12 | var src = pre.getAttribute('data-src');
|
13 | var a = document.createElement('a');
|
14 | a.textContent = pre.getAttribute('data-download-link-label') || 'Download';
|
15 | a.setAttribute('download', '');
|
16 | a.href = src;
|
17 | return a;
|
18 | });
|
19 |
|
20 | }());
|