@eventuras/scribo-code-prism
Prism as a syntax highlighter for the code blocks of @eventuras/scribo-core, on Lexical's @lexical/code-prism. Lexical is pinned to exactly the version Payload CMS uses (0.50.0 today).
pnpm add @eventuras/scribo-core @eventuras/scribo-code-prism
Use
import { codeBlocks } from "@eventuras/scribo-core/extensions/code";import { prismHighlighter } from "@eventuras/scribo-code-prism";// The language list for a picker, and plain code:dependencies: [...codeBlocks({ highlighter: prismHighlighter })];// The same, with the code coloured:dependencies: [...codeBlocks({ highlighter: prismHighlighter, highlight: true })];
prismHighlighter gives the core:
- the language list (C, C-like, C++, CSS, Go, HTML, Java, JavaScript, Markdown, Objective-C, Plain Text, PowerShell, Python, Rust, SQL, Swift, TypeScript, XML),
- normalisation of aliases, such as
tstotypescript, - Lexical's
CodePrismExtension, which is loaded only withhighlight: true.
@eventuras/scribo-markdown uses it for its language picker, with highlighting off.
Colours
Highlighted tokens get the class names in the editor theme's codeHighlight map (theme.codeHighlight.keyword, …). This package ships no stylesheet; style those classes in your app.
Languages
@lexical/code-prism loads the grammars for the languages listed above. A code block in another language stays plain.
To highlight more languages, add prismjs to your app's dependencies and import the grammar there, after this package:
import "@eventuras/scribo-code-prism";import "prismjs/components/prism-ruby";
Your app has to depend on prismjs itself: with pnpm's isolated installs it cannot import a package that only a dependency depends on. Keep it on the same version that @lexical/code-prism resolves to, so both use one Prism.
License
MIT