rehype-pretty / rehype-pretty-code

Beautiful code blocks for Markdown or MDX.

Home Page:https://rehype-pretty.pages.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add custom languages

mateusfg7 opened this issue · comments

How can I add syntax highlight for a new custom language?

I follow this guide: https://shiki.style/guide/load-lang. And this guide: https://rehype-pretty-code.netlify.app/#custom-highlighter
But any of that seems to work.

My config

const options: Partial<Options> = {
  theme: {
    dark: 'github-dark',
    light: 'github-light'
  },
  onVisitLine(node) {
    // Prevent lines from collapsing in `display: grid` mode, and
    // allow empty lines to be copy/pasted
    if (node.children.length === 0) {
      node.children = [{ type: 'text', value: ' ' }]
    }
  },
  getHighlighter: options =>
    getHighlighter({
      ...options,
      langs: [
        async () =>
          JSON.parse(
            await readFile('./content/plugin/visualg.tmLanguage.json', 'utf-8')
          )
      ]
    })
}

The result:

image

Works when I use fs.readFileSync instead of await readFile()