This plugin allows you to prefix Prism default classes (.comment
will become .namespace--comment
) or replace them with your defined ones (like .editor__comment
or .comment_7sh3a
).
Prism default classes are sensible but fixed and too generic. This plugin provide some ways to customize those classes to suit your needs. Example usages:
.prism--comment
) to avoid conflict with your existing classes.
.editor__comment
.
.comment_7sh3a
.
This plugin currently provides 2 features:
Prism.plugins.customClass.prefix('prism--')
Prism.plugins.customClass.map({
keyword: 'special-keyword',
string: 'string_ch29s',
comment: 'comment_93jsa'
})
Object's keys are the tokens you want to replace (eg: comment
), with their values being the classes you want to use (eg: my-comment
). Tokens which are not specified will stay the same.
Feature functions must be called AFTER Prism and this plugin. For example:
<!-- 1. load prism -->
<script src="prism.js"></script>
<!-- 2. load the plugin if you don't include it inside prism when download -->
<script src="plugins/custom-class/custom-class.js"></script>
<!-- 3. call the feature you want to use -->
<script>
Prism.plugins.customClass.map(myClassMap);
Prism.plugins.customClass.prefix(myPrefixString);
</script>
.my-namespace--comment_93jsa
).The initial purpose of this plugin is to be used with CSS Modules. It works perfectly with the class map object returned by CSS Modules. For example:
import Prism from 'prismjs';
import classMap from 'styles/editor-class-map.css';
Prism.plugins.customClass.map(classMap)
<pre class="language-javascript"><code>
var foo = 'bar';
</code></pre>
Prism.plugins.customClass.map({
keyword: 'special-keyword',
string: 'my-string'
});
Prism.plugins.customClass.prefix('pr-');
<pre class="language-javascript"><code>
<span class="pr-token pr-special-keyword">var</span>
foo
<span class="pr-token pr-operator">=</span>
<span class="pr-my-string">'bar'</span>
<span class="pr-token pr-punctuation">;</span>
</code></pre>