FIameCaster / prism-code-editor

Lightweight, extensible code editor component for the web using Prism
https://prism-code-editor.netlify.app
MIT License
58 stars 8 forks source link

Add language via prism definition #4

Closed qiushiyan closed 11 months ago

qiushiyan commented 11 months ago

Hi, thanks for creating the library.

I want to register a custom language. What I have is a prism language definition as in https://prismjs.com/extending.html, I am not sure how to convert it to the languageMap object mentioned in the docs.

It seems vite is automatically generating the grammar definition from prism definition in the build process. I think it's better to had a option to add a language that simply accepts the prism definition format at run time.

FIameCaster commented 11 months ago

The languageMap has nothing to do with Prism. It's for defining the bahavior of automatic indentation and comment toggling for a language. https://github.com/FIameCaster/prism-code-editor?tab=readme-ov-file#language-specific-behavior

If you want to add your own grammar definitions, just import the Prism core. Maybe I should make it clear in the readme that you can do this.

import { Prism } from "prism-code-editor"

Prism.languages.whatever = {
  ...
}

Just be sure to add your grammar before creating any editors.