File Highlight

Fetch external files and highlight them with Prism. Used on the Prism website itself.

How to use

Use the data-src attribute on empty <pre> elements, like so:

<pre data-src="myfile.js"></pre>

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).

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.

When used in conjunction with the Toolbar plugin, this plugin can also display a button to download the file. To use it, add a data-download-link attribute on the <pre> element.
Optionally, the text can also be customized by using a data-download-link-label attribute.

<pre data-src="myfile.js" data-download-link data-download-link-label="Download this file"></pre>


The plugin’s JS code:


This page:


File that doesn’t exist:


With a download button:


For more examples, browse around the Prism website. Most large code samples are actually files fetched with this plugin.