Skip to content

Commit

Permalink
File Highlight: Fix issue causing the Download button to show up on e…
Browse files Browse the repository at this point in the history
…very code blocks.
  • Loading branch information
Golmote committed Apr 17, 2018
1 parent b94f01f commit cd22499
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
25 changes: 15 additions & 10 deletions plugins/file-highlight/prism-file-highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,24 @@
}
};

if (pre.hasAttribute('data-download-link') && Prism.plugins.toolbar) {
Prism.plugins.toolbar.registerButton('download-file', function () {
var a = document.createElement('a');
a.textContent = pre.getAttribute('data-download-link-label') || 'Download';
a.setAttribute('download', '');
a.href = src;
return a;
});
}

xhr.send(null);
});

if (Prism.plugins.toolbar) {
Prism.plugins.toolbar.registerButton('download-file', function (env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName) || !pre.hasAttribute('data-src') || !pre.hasAttribute('data-download-link')) {
return;
}
var src = pre.getAttribute('data-src');
var a = document.createElement('a');
a.textContent = pre.getAttribute('data-download-link-label') || 'Download';
a.setAttribute('download', '');
a.href = src;
return a;
});
}

};

document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);
Expand Down
2 changes: 1 addition & 1 deletion plugins/file-highlight/prism-file-highlight.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,19 +849,24 @@ Prism.languages.js = Prism.languages.javascript;
}
};

if (pre.hasAttribute('data-download-link') && Prism.plugins.toolbar) {
Prism.plugins.toolbar.registerButton('download-file', function () {
var a = document.createElement('a');
a.textContent = pre.getAttribute('data-download-link-label') || 'Download';
a.setAttribute('download', '');
a.href = src;
return a;
});
}

xhr.send(null);
});

if (Prism.plugins.toolbar) {
Prism.plugins.toolbar.registerButton('download-file', function (env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName) || !pre.hasAttribute('data-src') || !pre.hasAttribute('data-download-link')) {
return;
}
var src = pre.getAttribute('data-src');
var a = document.createElement('a');
a.textContent = pre.getAttribute('data-download-link-label') || 'Download';
a.setAttribute('download', '');
a.href = src;
return a;
});
}

};

document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);
Expand Down

0 comments on commit cd22499

Please sign in to comment.