JSPM

gatsby-remark-prismjs

1.0.0-alpha21
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 20828
  • Score
    100M100P100Q148234F
  • License MIT

Adds syntax highlighting to code blocks at build time using PrismJS

Package Exports

  • gatsby-remark-prismjs
  • gatsby-remark-prismjs/highlight-code
  • gatsby-remark-prismjs/highlight-code.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gatsby-remark-prismjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gatsby-remark-prismjs

Adds syntax highlighting to code blocks in markdown files using PrismJS.

Install

npm install --save gatsby-remark-prismjs

How to use

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        `gatsby-remark-prismjs`,
      ]
    }
  }
]

In a markdown file:

This is some beautiful code:

```javascript
// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        `gatsby-remark-prismjs`,
      ]
    }
  }
]
```

You can also add line highlighting. It adds a span around lines of
code with a special class (.highlight-code-line) that you can
target with styles.

In the following code snippit, lines 1 and 4 through 6 will get
the line highlighting. The line range parsing is done with
https://www.npmjs.com/package/parse-numeric-range.

```javascript{1,4-6}
// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        `gatsby-remark-prismjs`,
      ]
    }
  }
]

PrismJS themes

You'll also need to add a PrismJS theme. Prism ships with a number of themes you can try or you can build your own by copying and modifying an example (what we've done on gatsbyjs.org).

To load a theme, simply require its CSS file in your layouts/default.js file.

E.g.

// layouts/default.js
require('prismjs/themes/prism-solarizedlight.css')