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