-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made the download button its own plugin (#1840)
This makes the download button its own plugin instead of being part of File highlight.
- Loading branch information
1 parent
d49f0f2
commit c6c62a6
Showing
9 changed files
with
86 additions
and
46 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
|
||
<meta charset="utf-8" /> | ||
<link rel="icon" href="favicon.png" /> | ||
<title>Download Button ▲ Prism plugins</title> | ||
<base href="../.." /> | ||
<link rel="stylesheet" href="style.css" /> | ||
<link rel="stylesheet" href="themes/prism.css" data-noprefix /> | ||
<link rel="stylesheet" href="plugins/toolbar/prism-toolbar.css" data-noprefix /> | ||
<script src="scripts/prefixfree.min.js"></script> | ||
|
||
<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script> | ||
<script src="https://www.google-analytics.com/ga.js" async></script> | ||
</head> | ||
<body> | ||
|
||
<header> | ||
<div class="intro" data-src="templates/header-plugins.html" data-type="text/html"></div> | ||
|
||
<h2>Download Button</h2> | ||
<p>A button in the toolbar of a code block adding a convenient way to download a code file.</p> | ||
</header> | ||
|
||
<section class="language-markup"> | ||
<h1>How to use</h1> | ||
|
||
<p>Use the <code>data-src</code> and <code>data-download-link</code> attribute on a <code><pre></code> elements similar to <a href="plugins/autoloader/">Autoloader</a>, like so:</p> | ||
|
||
<pre><code><pre data-src="myfile.js" data-download-link></pre></code></pre> | ||
|
||
<p>Optionally, the text of the button can also be customized by using a <code>data-download-link-label</code> attribute.</p> | ||
<pre><code><pre data-src="myfile.js" data-download-link data-download-link-label="Download this file"></pre></code></pre> | ||
</section> | ||
|
||
<section> | ||
<h1>Examples</h1> | ||
|
||
<p>The plugin’s JS code:</p> | ||
<pre data-src="plugins/download-button/prism-download-button.js" data-download-link data-download-link-label="Download the code!"></pre> | ||
|
||
<p>This page:</p> | ||
<pre data-src="plugins/file-highlight/index.html" data-download-link></pre> | ||
</section> | ||
|
||
<footer data-src="templates/footer.html" data-type="text/html"></footer> | ||
|
||
<script src="prism.js"></script> | ||
<script src="plugins/toolbar/prism-toolbar.js"></script> | ||
<script src="plugins/download-button/prism-download-button.js"></script> | ||
<script src="scripts/utopia.js"></script> | ||
<script src="components.js"></script> | ||
<script src="scripts/code.js"></script> | ||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(function () { | ||
if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) { | ||
return; | ||
} | ||
|
||
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; | ||
}); | ||
|
||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters