@pborenstein/eleventy-md-syntax-highlight
v1.1.0
Published
PrismJS highlights with line numbers for Eleventy
Downloads
150
Maintainers
Readme
eleventy-md-syntax-highlight
PrismJS markdown syntax highlighting with optional line numbers for Eleventy.
The differences between the official syntax highlighting plugin and this plugin are:
- Handles only Markdown code fences
- Provides optional line numbers
- Does not highlight lines
Installation
npm i @pborenstein/eleventy-md-syntax-highlight --save-dev
Configuration
In your Eleventy configuration file
(typically .eleventy.js
)
install the plugin like this.
const syntaxHighlight = require('eleventy-md-syntax-highlight')
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight,
{ showLineNumbers: false })
}
| When showLineNumbers
is… | This is what happens… |
| :------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| false
(default) | Code fences do not have line numbers by default. You can enable line numbers for a specific code fence by appending a hash mark (#
) after the language. |
| true
| Every code fence has line numbers. You cannot disable line numbers for a specific code fence. |
Styles
This plugin uses unedited PrismJS CSS files. You can get the CSS two ways:
A: Download the CSS from the PrismJS site
- Go to the PrismJS downloads page.
- Select a PrismJS theme.
- Select the Line Numbers plugin.
- Click the Download CSS button to download a single CSS file that contains the theme and the line number styles. (You don't need the JS files.)
B: Get the files from the PrismJS repo.
- Get a theme CSS file
- Get the line numbers CSS file
prism-line-numbers.css
Markup
This is how you mark up code fences.
If showLineNumbers
is false
, append a
hash mark (#
) to the language.
```json#
collections: {
"all": [ items ],
"categories": {
"Culture": [ items ],
"Life": [ items ],
"Thinking": [ items ]
}
}
```
Which will render like this:
To start with a specific line number,
add it after the hash mark (#
).
The line numbers for this code fence
will start st 28:
```json#28
collections: {
"all": [ items ],
"categories": {
"Culture": [ items ],
"Life": [ items ],
"Thinking": [ items ]
}
}
```
As you can see here:
Credits
- Zach Leatherman (@zachleat): official Eleventy plugin
- Anders Grendstadbakk (@andeersg): How to do it