Hash :
d38592c5
Author :
Date :
2021-10-04T08:52:52
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="assets/favicon.png" />
<title>File Highlight ▲ Prism plugins</title>
<base href="../.." />
<link rel="stylesheet" href="assets/style.css" />
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
<link rel="stylesheet" href="plugins/line-numbers/prism-line-numbers.css" data-noprefix />
<script src="assets/vendor/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 data-plugin-header="file-highlight"></header>
<section class="language-markup">
<h1>How to use</h1>
<p>Use the <code>data-src</code> attribute on empty <code><pre></code> elements, like so:</p>
<pre><code><pre data-src="myfile.js"></pre></code></pre>
<p>You don’t need to specify the language, it’s automatically determined by the file extension.
If, however, the language cannot be determined from the file extension or the file extension is incorrect, you may specify a language as well (with the usual class name way).</p>
<p>Use the <code>data-range</code> attribute to display only a selected range of lines from the file, like so:</p>
<pre><code><pre data-src="myfile.js" data-range="1,5"></pre></code></pre>
<p>Lines start at 1, so <code>"1,5"</code> will display line 1 up to and including line 5. It's also possible to specify just a single line (e.g. <code>"5"</code> for just line 5) and open ranges (e.g. <code>"3,"</code> for all lines starting at line 3). Negative integers can be used to specify the n-th last line, e.g. -2 for the second last line.</p>
<p>When <code>data-range</code> is used in conjunction with the <a href="plugins/line-numbers">Line Numbers plugin</a>, this plugin will add the proper <code>data-start</code> according to the specified range. This behavior can be overridden by setting the <code>data-start</code> attribute manually.</p>
<p>Please note that the files are fetched with XMLHttpRequest. This means that if the file is on a different origin, fetching it will fail, unless CORS is enabled on that website.</p>
</section>
<section>
<h1>Examples</h1>
<p>The plugin’s JS code:</p>
<pre data-src="plugins/file-highlight/prism-file-highlight.js"></pre>
<p>This page:</p>
<pre data-src="plugins/file-highlight/index.html"></pre>
<p>File that doesn’t exist:</p>
<pre data-src="foobar.js"></pre>
<p>With line numbers, and <code>data-range="12,111"</code>:</p>
<pre data-src="plugins/file-highlight/prism-file-highlight.js" data-range="12,111" class="line-numbers"></pre>
<p>For more examples, browse around the Prism website. Most large code samples are actually files fetched with this plugin.</p>
</section>
<footer data-src="assets/templates/footer.html" data-type="text/html"></footer>
<script src="prism.js"></script>
<!-- The File Highlight plugin is already included into Prism.js build -->
<script src="plugins/line-numbers/prism-line-numbers.js"></script>
<script src="assets/vendor/utopia.js"></script>
<script src="components.js"></script>
<script src="assets/code.js"></script>
</body>
</html>