Added Line Range plugin and index.html for example #1810
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fetch Line Range
A plugin for Prism.js -
Efficiently display a range of line numbers from a fetched source file
See an example here. Source for this example in the docs/ folder
How to use
Include prism-line-range.js in your markup after you call prism.js
Adding a
data-fetch
anddata-range
attribute to an empty<pre>
will trigger Fetch Line Numbers. Thedata-fetch
attribute takes a filepath or valid URL, and thedata-range
attribute expects a comma separated value of integers that describe the desired range of lines to display (1,15
). The markup for some code chunks might look like this:The first block would display the first 5 lines.
The second block would be lines 6-10
Line Numbers plugin support
Fetch Line Range automatically inserts the correct
data-start
parameter for use with the Line Numbers plugin. This way, the line numbers displayed will correspond correctly with the code file that was fetched. you can override this functionality by setting thedata-start
attribute on your<pre>
element manually, and Fetch Line Range will use it instead of injecting a value.Caveats
Whitespace Normalization: If you are using the Whitespace Normalization plugin with Prism, leading and trailing empty lines are stripped even if included
data-range
attribute. This does not affect the line numbering.fetch() and Promise: Under the hood, Fetch Line Range uses
fetch()
andPromise
which are (wtf let's get a move on =) not supported by all browser environments. For these cases there is a minified version with Promises and fetch() polyfilled in the smallest manner I could find (in my home repo). The resulting polyfilled plugin is a whopping 10.8kb, compared to without the polyfills of ~1.6kb.