2

I use Rehype Pretty Code for the website with nextjs. How to use light dark theme. Below is the configuration file

const rehypePrettyCodeOptions: Partial<Options> = {
  theme: {
    dark: JSON.parse(
      fs.readFileSync(require.resolve('https://raw.githubusercontent.com/shikijs/shiki/main/packages/shiki/themes/github-dark.json'), 'utf-8')
    ),
    light: JSON.parse(
      fs.readFileSync(require.resolve('https://raw.githubusercontent.com/shikijs/shiki/main/packages/shiki/themes/github-light.json'), 'utf-8')
  ),

  onVisitHighlightedLine(node) {
    node.properties.className.push("line--highlighted")
  },
  onVisitHighlightedWord(node) {
    node.properties.className = ["word--highlighted"]
  },
};

how does it work.

Alex Cuba
  • 73
  • 4
  • check out the docs here if it helps: https://rehype-pretty-code.netlify.app/#:~:text=Multiple%20themes%20(dark/light%20mode) – Gangula Jun 24 '23 at 20:14

0 Answers0