Skip to content

About

Starter template for third-party highlight.js language grammars

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

[your grammar] - a language grammar for highlight.js

Starter repository for a third-party highlight.js grammar.

Rename example (file, folder, package.json name / main, and registerLanguage id) to your grammar.

Usage

Simply include the Highlight.js library in your webpage or Node app, then load this module.

Static website or simple usage

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>

Using directly from the UNPKG CDN

<script type="text/javascript"
  src="https://unpkg.com/highlightjs-your-grammar/dist/example.min.js"></script>

With Node or another build system

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();

Develop

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 install

Markup tests for extras:

ONLY_EXTRA=true npm run test-markup

CDN file (dist/example.min.js):

node tools/build.js -t cdn

Commit 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 build

That writes dist/example.es.js, dist/example.cjs, and the CDN build dist/example.js (hljs.registerLanguage at the bottom). Commit them.

License

MIT. See LICENSE.

About

Starter template for third-party highlight.js language grammars

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages