Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

A plugin to syntax highlighting code blocks with gatsby-transform-remark by using shiki.

Notifications You must be signed in to change notification settings

enpitsuLin/gatsby-remark-shiki

Repository files navigation

gatsby-remark-shiki

npm

A plugin to syntax highlighting code blocks with gatsby-transform-remark for Gatsby that uses shiki

中文|English

Getting started

Install the package

npm install @enpitsulin/gatsby-remark-shiki
// or use yarn
yarn add @enpitsulin/gatsby-remark-shiki

Add to your gatsby-config.js

{
  // ...
  plugins:[
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        `@enpitsulin/gatsby-remark-shiki`,
      ]
    }
  ]
}
// or
{
  // ...
  plugins:[
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        {
          resolve: `@enpitsulin/gatsby-remark-shiki`,
          options: {/* here for custom option */}
        }
      ]
    }
  ]
}

Then you can write code in your markdown file like this:

```javascript
function funName() {
  console.log("this is a code snippet");
}
```

Options

You can configure the plugin option to change theme or alias a language

Multi Theme Support

You can use built-in code highlight theme by change theme option, for example.

{
  theme: "one-dark-pro"; //default 'nord';
}

You can preview some of these themes on https://vscodethemes.com/

Theming with theme file

To Do

Theming with CSS variables

First change theme option to css-variables,than create css which define these CSS variables file and require it in your gatsby-browser.js, e.g.

/* shiki-variables */
:root {
  --shiki-color-text: #eeeeee;
  --shiki-color-background: #333333;
  --shiki-token-constant: #660000;
  --shiki-token-string: #770000;
  --shiki-token-comment: #880000;
  --shiki-token-keyword: #990000;
  --shiki-token-parameter: #aa0000;
  --shiki-token-function: #bb0000;
  --shiki-token-string-expression: #cc0000;
  --shiki-token-punctuation: #dd0000;
  --shiki-token-link: #ee0000;
}
// gatsby-browser.js
require("path/to/shiki-variables.css");

Language Alias

This lets you set up language aliases. For example, settings below will let you use the language superscript which will highlight using the javascript highlighter

{
  aliases: {
    superscript: "javascript";
  }
}

Contributing

To do

License

MIT © enpitsuLin

About

A plugin to syntax highlighting code blocks with gatsby-transform-remark by using shiki.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published