prism-syntax
Use when adding syntax highlighting for custom languages to Prism.js, used by Docusaurus and many documentation sites
When & Why to Use This Skill
This Claude skill streamlines the process of adding custom language syntax highlighting to Prism.js, a popular library used by Docusaurus and various documentation platforms. It provides expert guidance on defining token types, implementing advanced regex patterns like lookbehind and greedy matching, and seamlessly integrating custom grammars into your documentation workflow to enhance code readability.
Use Cases
- Creating custom syntax highlighting for proprietary or niche Domain Specific Languages (DSLs) in technical documentation.
- Configuring Docusaurus projects to support additional languages by modifying docusaurus.config.js and theme files.
- Implementing complex language tokenization using advanced Prism.js pattern techniques such as nested grammars and lookbehinds.
- Optimizing documentation SEO and user experience by ensuring all code snippets are correctly highlighted and categorized.
| name | prism-syntax |
|---|---|
| description | Use when adding syntax highlighting for custom languages to Prism.js, used by Docusaurus and many documentation sites |
Prism.js Syntax Highlighting
Quick Start
Prism.languages.mylang = {
'comment': /\/\/.*/,
'string': /"(?:\\.|[^"\\])*"/,
'keyword': /\b(?:if|else|while|for|return)\b/,
'number': /\b\d+(?:\.\d+)?\b/,
'operator': /[+\-*/%=<>!&|]+/,
'punctuation': /[{}[\];(),.:]/
};
Token Types (CSS Classes)
comment- Commentsstring- String literalskeyword- Language keywordsnumber- Numeric literalsoperator- Operatorspunctuation- Punctuation marksfunction- Function namesclass-name- Type/class namesproperty- Object propertiesboolean- true/falsebuiltin- Built-in functions
Pattern Techniques
{
// Lookbehind for context
'function': {
pattern: /(\bfunction\s+)\w+/,
lookbehind: true
},
// Nested grammar
'interpolation': {
pattern: /\$\{[^}]+\}/,
inside: {
'variable': /\$\{|\}/,
'expression': { pattern: /[\s\S]+/, inside: Prism.languages.javascript }
}
},
// Greedy matching
'string': { pattern: /"(?:\\.|[^"\\])*"/, greedy: true }
}
Docusaurus Integration
// docusaurus.config.js
module.exports = {
themeConfig: {
prism: {
additionalLanguages: ['mylang'],
theme: require('prism-react-renderer').themes.github,
}
}
};
// Create src/prism/prism-mylang.js and import in src/theme/prism-include-languages.js
Reference Files
- references/tokens.md - Complete token reference
- references/patterns.md - Advanced pattern techniques
- references/docusaurus.md - Docusaurus integration