Starter repository for a third-party highlight.js grammar.
Rename example (file, folder, package.json name / main, and registerLanguage id) to your grammar.
Simply include the Highlight.js library in your webpage or Node app, then load this module.
Simply load the module after loading Highlight.js. You'll use the minified version found in the dist directory. This module is just a CDN build of the grammar, so it will register itself as the Javascript is loaded.
<script type="text/javascript" src="/path/to/highlight.min.js"></script>
<script type="text/javascript" src="/path/to/example.js"></script>
<script type="text/javascript">
hljs.highlightAll();
</script><script type="text/javascript"
src="https://unpkg.com/highlightjs-your-grammar/dist/example.min.js"></script>- More info: https://unpkg.com
If you're using Node / Webpack / Rollup / Browserify, etc, simply load the grammar module, then register it with Highlight.js.
CommonJS (Highlight.js v11):
var hljs = require('highlight.js');
var hljsExample = require('highlightjs-grammar-template');
hljs.registerLanguage("example", hljsExample);
hljs.highlightAll();ESM:
import hljs from 'highlight.js';
import hljsExample from 'highlightjs-grammar-template';
hljs.registerLanguage("example", hljsExample);
hljs.highlightAll();Clone highlight.js and clone this repo into extra/:
git clone https://github.com/highlightjs/highlight.js.git
cd highlight.js
git clone https://github.com/highlightjs/highlightjs-grammar-template.git extra/highlightjs-grammar-template
npm installMarkup tests for extras:
ONLY_EXTRA=true npm run test-markupCDN file (dist/example.min.js):
node tools/build.js -t cdnCommit the generated dist/ files.
In this repo, npm test / npm run test-markup installs highlight.js from npm, builds the ESM bundle, and runs markup fixtures against dist/example.es.js.
Self-contained ESM build (no highlight.js checkout):
npm run buildThat writes dist/example.es.js, dist/example.cjs, and the CDN build dist/example.js (hljs.registerLanguage at the bottom). Commit them.
MIT. See LICENSE.