prism-download-button.js 605 B

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