@@ -23,12 +23,36 @@ You are responsible for including [your favorite PrismJS theme CSS](https://gith
2323
2424Read more about [ Eleventy plugins.] ( https://www.11ty.io/docs/plugins/ )
2525
26+ ### Options
27+
28+ Optionally pass in an options object as the second argument to ` addPlugin ` to further customize this plugin pack.
29+
30+ ```
31+ const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
32+ module.exports = function(eleventyConfig) {
33+ eleventyConfig.addPlugin(syntaxHighlight, {
34+
35+ // Change which syntax highlighters are installed
36+ templateFormats: ["*"], // default
37+
38+ // Or, just njk and md syntax highlighters (do not install liquid)
39+ // templateFormats: ["njk", "md"],
40+
41+ // init callback lets you customize Prism
42+ init: function({ Prism }) {
43+ Prism.languages.myCustomLanguage = /* */;
44+ }
45+ });
46+ };
47+ ```
48+
2649## Usage
2750
2851### This plugin provides:
2952
3053* Markdown Highlighter: syntax highlights using PrismJS
31- * Liquid Tag ` {% highlight %} ` : syntax highlights using PrismJS.
54+ * Liquid Custom Tag ` {% highlight %} ` : syntax highlights using PrismJS.
55+ * Nunjucks Paired Shortcode ` {% highlight %} ` : syntax highlights using PrismJS.
3256
3357### Markdown Highlighter
3458
@@ -37,6 +61,7 @@ Optionally specify a language after the start of the markdown fenced code block.
3761* [ List of supported PrismJS languages] ( http://prismjs.com/#languages-list )
3862
3963````
64+ <!-- Markdown Template -->
4065``` js
4166function myFunction() {
4267 return true;
@@ -45,8 +70,12 @@ function myFunction() {
4570````
4671
4772````
48- // Line highlighting classes (single highlight)
49- // Adds `highlight-line-active` class to lines 1,3,4,5 (for line highlighting)
73+ <!--
74+ Line highlighting classes (single highlight)
75+ Adds `highlight-line-active` class to lines 1,3,4,5 (for line highlighting)
76+ -->
77+
78+ <!-- Markdown Template -->
5079``` js/1,3-5
5180function myFunction() {
5281 // …
@@ -56,9 +85,13 @@ function myFunction() {
5685````
5786
5887````
59- // Line highlighting classes (add and remove mode)
60- // Adds `highlight-line-add` class to lines 1,3
61- // Adds `highlight-line-remove` class to lines 5,6,7,8
88+ <!--
89+ Line highlighting classes (add and remove mode)
90+ Adds `highlight-line-add` class to lines 1,3
91+ Adds `highlight-line-remove` class to lines 5,6,7,8
92+ -->
93+
94+ <!-- Markdown Template -->
6295``` js/1,3/5-8
6396function myFunction() {
6497 // …
@@ -85,6 +118,7 @@ function myFunction() {
85118* [ List of supported PrismJS languages] ( http://prismjs.com/#languages-list )
86119
87120```
121+ <!-- Liquid Template -->
88122{% highlight js %}
89123function myFunction() {
90124 return true;
@@ -93,8 +127,12 @@ function myFunction() {
93127```
94128
95129```
96- // Line highlighting classes (single highlight)
97- // Adds `highlight-line-active` class to lines 1,3,4,5 (for line highlighting)
130+ <!--
131+ Line highlighting classes (single highlight)
132+ Adds `highlight-line-active` class to lines 1,3,4,5 (for line highlighting)
133+ -->
134+
135+ <!-- Liquid Template -->
98136{% highlight js 1,3-5 %}
99137function myFunction() {
100138 // …
@@ -104,9 +142,13 @@ function myFunction() {
104142```
105143
106144```
107- // Line highlighting classes (add and remove)
108- // Adds `highlight-line-add` class to lines 1,3
109- // Adds `highlight-line-remove` class to lines 5,6,7,8
145+ <!--
146+ Line highlighting classes (add and remove)
147+ Adds `highlight-line-add` class to lines 1,3
148+ Adds `highlight-line-remove` class to lines 5,6,7,8
149+ -->
150+
151+ <!-- Liquid Template -->
110152{% highlight js 1,3 5-8 %}
111153function myFunction() {
112154 // …
@@ -120,6 +162,7 @@ function myFunction() {
120162Use ` text ` to use the line highlighting features without PrismJS.
121163
122164```
165+ <!-- Liquid Template -->
123166{% highlight text 1-2 %}
124167function myFunction() {
125168 let highlighted = true;
@@ -128,16 +171,79 @@ function myFunction() {
128171{% endhighlight %}
129172```
130173
131- ### Sample Line Highlighting CSS
174+ ### Nunjucks Paired Shortcode: Prism Syntax Highlighter
175+
176+ * [ List of supported PrismJS languages] ( http://prismjs.com/#languages-list )
177+
178+ ```
179+ <!-- Nunjucks Template -->
180+ {% highlight "js" %}
181+ function myFunction() {
182+ return true;
183+ }
184+ {% endhighlight %}
185+ ```
132186
133187```
188+ <!--
189+ Line highlighting classes (single highlight)
190+ Adds `highlight-line-active` class to lines 1,3,4,5 (for line highlighting)
191+ -->
192+
193+ <!-- Nunjucks Template -->
194+ {% highlight "js 1,3-5" %}
195+ function myFunction() {
196+ // …
197+ return true;
198+ }
199+ {% endhighlight %}
200+ ```
201+
202+ ```
203+ <!--
204+ Line highlighting classes (add and remove)
205+ Adds `highlight-line-add` class to lines 1,3
206+ Adds `highlight-line-remove` class to lines 5,6,7,8
207+ -->
208+
209+ <!-- Nunjucks Template -->
210+ {% highlight "js 1,3 5-8" %}
211+ function myFunction() {
212+ // …
213+ return true;
214+ }
215+ {% endhighlight %}
216+ ```
217+
218+ #### Plain text
219+
220+ Use ` text ` to use the line highlighting features without PrismJS.
221+
222+ ```
223+ <!-- Nunjucks Template -->
224+ {% highlight "text 1-2" %}
225+ function myFunction() {
226+ let highlighted = true;
227+ return highlighted;
228+ }
229+ {% endhighlight %}
230+ ```
231+
232+ ### Sample Line Highlighting CSS
233+
234+ ``` css
134235.highlight-line {
135236 display : block ;
136- padding: 0.125em 1em;
137237 text-decoration : none ; /* override del, ins, mark defaults */
138238 color : inherit ; /* override del, ins, mark defaults */
139239}
140- .highlight-line:not(:empty) + br {
240+
241+ /* allow highlighting empty lines */
242+ .highlight-line :empty :before {
243+ content : " " ;
244+ }
245+ /* avoid double line breaks when using display: block; */
246+ .highlight-line + br {
141247 display : none ;
142248}
143249
0 commit comments