### Basic Download Button Setup Source: https://github.com/prismjs/prism/blob/v2/src/plugins/download-button/README.md Use the `data-src` and `data-download-link` attributes on a `
` element to enable the download button. This is the basic setup for the plugin.
```html
```
--------------------------------
### Include WebPlatform Docs Plugin
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/wpd/README.md
No setup required, just include the plugin in your download.
```markup
```
```markup
```
```markup
```
```markup
```
--------------------------------
### Stylus Previewer Examples
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/previewers/README.md
Presents examples of how previewers function with Stylus syntax, covering gradients, angles, colors, easing functions, and time durations. It showcases various gradient types and transform properties.
```stylus
gradient = linear-gradient(135deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%)
.example-gradient
background-image: repeating-radial-gradient(circle, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1) 10px, rgba(255, 0, 0, 0) 20px)
angle = 357deg
.example-angle
transform: rotate(100grad)
color = olive
.example-color
color: #000
easing = ease-in
.example-easing
transition-timing-function: ease-out
time = 3s
.example-time
transition-duration: 0.5s
```
--------------------------------
### Sass Previewer Examples
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/previewers/README.md
Shows how previewers work with Sass variables and mixins for gradients, angles, colors, easing functions, and time durations. Includes various gradient and transform examples.
```sass
$gradient: linear-gradient(135deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%)
@mixin example-gradient
background: -moz-radial-gradient(center, ellipse cover, #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%)
background: radial-gradient(ellipse at center, #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%)
$angle: 380grad
@mixin example-angle
transform: rotate(-120deg)
.example-angle
transform: rotate(18rad)
$color: blue
@mixin example-color
color: rgba(147, 32, 34, 0.8)
.example-color
color: pink
$easing: ease-out
.example-easing
transition-timing-function: ease-in-out
$time: 3s
@mixin example-time
transition-duration: 800ms
.example-time
transition-duration: 0.8s
```
--------------------------------
### Basic Object Example
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/normalize-whitespace/demo.md
A simple JavaScript object example demonstrating basic structure.
```javascript
let example = {
foo: true,
bar: false
};
```
--------------------------------
### CSS Previewer Examples
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/previewers/README.md
Demonstrates various CSS properties that trigger previewers for gradients, angles, colors, easing functions, and time durations. These examples showcase different syntaxes and browser prefixes for gradients.
```css
.example-gradient {
background: -webkit-linear-gradient(left, #cb60b3 0%, #c146a1 50%, #a80077 51%, #db36a4 100%); /* Chrome10+, Safari5.1+ */
background: -moz-linear-gradient(left, #cb60b3 0%, #c146a1 50%, #a80077 51%, #db36a4 100%); /* FF3.6+ */
background: -ms-linear-gradient(left, #cb60b3 0%, #c146a1 50%, #a80077 51%, #db36a4 100%); /* IE10+ */
background: -o-linear-gradient(left, #cb60b3 0%, #c146a1 50%, #a80077 51%, #db36a4 100%); /* Opera 11.10+ */
background: linear-gradient(to right, #cb60b3 0%, #c146a1 50%, #a80077 51%, #db36a4 100%); /* W3C */
}
.example-angle {
transform: rotate(10deg);
}
.example-color {
color: rgba(255, 0, 0, 0.2);
background: purple;
border: 1px solid hsl(100, 70%, 40%);
}
.example-easing {
transition-timing-function: linear;
}
.example-time {
transition-duration: 3s;
}
```
--------------------------------
### Show Invisibles HTML Example
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/show-invisibles/README.md
An example HTML structure demonstrating the use of Prism.js with the Show Invisibles plugin.
```html
Show Invisibles Example
// This is a comment with tabs:
// And some spaces:
// And a newline:
```
--------------------------------
### Line Highlight with Line Numbers Plugin
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/line-highlight/README.md
Shows compatibility with the Line Numbers plugin. This example highlights line 1 and starts line numbering from -5.
```markup
```
--------------------------------
### HTML Example with Links
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/autolinker/README.md
Demonstrates autolinking of URLs in HTML comments, attributes, and raw text content.
```html
Autolinking in raw text: https://prismjs.com
```
--------------------------------
### Line Numbers with Custom Start (HTML)
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/line-numbers/README.md
Use the 'data-start' attribute on the pre element to specify a custom starting line number. This example starts numbering from -5.
```html
```
--------------------------------
### Scss Previewer Examples
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/previewers/README.md
Demonstrates the integration of previewers with Scss, utilizing variables and interpolation for properties like background-image, transform, color, transition-timing-function, and transition-duration.
```scss
$gradient: linear-gradient(135deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%);
$attr: background;
.example-gradient {
#{$attr}-image: repeating-linear-gradient(10deg, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1) 10px, rgba(255, 0, 0, 0) 20px);
}
$angle: 1.8turn;
.example-angle {
transform: rotate(-3rad)
}
$color: blue;
.example-color {
#{$attr}-color: rgba(255, 255, 0, 0.75);
}
$easing: linear;
.example-easing {
transition-timing-function: cubic-bezier(0.9, 0.1, .2, .4);
}
$time: 1s;
.example-time {
transition-duration: 10s
}
```
--------------------------------
### JavaScript Example
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/match-braces/README.md
A basic JavaScript function demonstrating brace usage.
```js
const func = (a, b) => {
return `${a}:${b}`;
}
```
--------------------------------
### Example of Normalized Whitespace
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/normalize-whitespace/README.md
This example shows how code blocks are rendered after whitespace normalization, including trimming, indenting, and line breaking.
```javascript
let example = {
foo: true,
bar: false
};
let
there_is_a_very_very_very_very_long_line_it_can_break_it_for_you
= true;
if
(there_is_a_very_very_very_very_long_line_it_can_break_it_for_you
=== true) {
};
```
--------------------------------
### Example: Prefix and map classes
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/custom-class/README.md
Illustrates the combined effect of prefixing and mapping classes on code tokens, showing the transformation from input HTML to output with custom classes.
```javascript
Prism.plugins.customClass.map({
keyword: 'special-keyword',
string: 'my-string'
});
Prism.plugins.customClass.prefix('pr-');
```
--------------------------------
### Handling Non-existent Files
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/file-highlight/README.md
Example showing how an empty `` tag is rendered when the file specified in `data-src` does not exist.
```html
```
--------------------------------
### CSS Example with URL
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/autolinker/README.md
Illustrates how URLs within CSS, specifically in `url()` functions, are autolinked.
```css
@font-face {
src: url(https://lea.verou.me/logo.otf);
font-family: 'LeaVerou';
}
```
--------------------------------
### Plugin JavaScript File
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/file-highlight/README.md
Example of loading the plugin's own JavaScript file using `data-src`.
```html
```
--------------------------------
### Lisp Example
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/match-braces/README.md
A Lisp function for calculating factorial.
```lisp
(defun factorial (n)
(if (= n 0) 1
(* n (factorial (- n 1)))))
```
--------------------------------
### Custom Keyword CSS Example
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/highlight-keywords/README.md
Example CSS rule to style specific keywords like 'if' and 'return' with custom colors. You need to define these rules yourself as the plugin does not include styles.
```css
.token.keyword.keyword-return, .token.keyword.keyword-if {
/* Set the color to a nice red. */
color: #f92672;
}
```
--------------------------------
### Less Previewer Examples
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/previewers/README.md
Illustrates the use of previewers with Less variables and properties for gradients, angles, colors, easing functions, and time durations. Includes vendor-prefixed gradients.
```less
@gradient: linear-gradient(135deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%);
.example-gradient {
background: -webkit-linear-gradient(-45deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* Chrome10+, Safari5.1+ */
background: -moz-linear-gradient(-45deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* FF3.6+ */
background: -ms-linear-gradient(-45deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* IE10+ */
background: -o-linear-gradient(-45deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* Opera 11.10+ */
background: linear-gradient(135deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* W3C */
}
@angle: 3rad;
.example-angle {
transform: rotate(.4turn)
}
@nice-blue: #5B83AD;
.example-color {
color: hsla(102, 53%, 42%, 0.4);
}
@easing: cubic-bezier(0.1, 0.3, 1, .4);
.example-easing {
transition-timing-function: ease;
}
@time: 1s;
.example-time {
transition-duration: 2s;
}
```
--------------------------------
### Highlight with Line Number Offset
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/line-highlight/README.md
Use `data-line-offset` to adjust the starting line number for highlighting. This example highlights line 43 but starts numbering from line 41.
```markup
```
--------------------------------
### JavaScript Example with Links
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/autolinker/README.md
Shows various types of links (URLs, emails, Markdown links) within JavaScript comments and code.
```javascript
/**
* Prism: Lightweight, robust, elegant syntax highlighting
* MIT license https://www.opensource.org/licenses/mit-license.php/
* @author Lea Verou https://lea.verou.me
* Reach Lea at fake@email.com (no, not really)
* And this is [a Markdown link](https://prismjs.com). Sweet, huh?
*/
let foo = 5;
// And a single line comment https://google.com
```
--------------------------------
### Markup Attribute Example
Source: https://github.com/prismjs/prism/blob/v2/src/plugins/previewers/README.md
Shows how previewers can be triggered by values within HTML attributes, such as 'bgcolor' and 'style'.
```html