highlight.js (syntax highlighting for the Web) support for Cedar based on Grammar specification for Cedar policy syntax and for Cedar human-readable schema based on Grammar specification for human-readable schemas. Project structure derived from language contributor checklist and mapped to the Stylable Scopes.
See it in action on https://docs.cedarpolicy.com/
Web browser <script src=>
usage example from test/static/index.html
(adjust the script src
paths as required):
<script src="highlight.min.js"></script>
<script src="hljs-cedar.min.js"></script>
<script type="text/javascript">
window.onload = () => {
hljs.registerLanguage('cedar', hljsCedar);
hljs.registerLanguage('cedarschema', hljsCedarschema);
hljs.highlightAll();
};
</script>
ECMAScript module import
usage example from test/vite/index.html
(adjust the import from
paths as required):
import hljs from 'highlight.js';
import { hljsCedar, hljsCedarschema } from 'hljs-cedar.mjs';
hljs.registerLanguage('cedar', hljsCedar);
hljs.registerLanguage('cedarschema', hljsCedarschema);
hljs.highlightAll();
Install the project dependencies using npm install
.
src/cedar.js
is the main source file in ECMAScript module format.
The npm run build
script uses esbuildto create multiple files in the dist
folder:
hljs-cedar.js
- Web browser<script src=>
compatible version. Setswindow.hljsCedar
andwindow.hljsCedarschema
to highlight functions.hljs-cedar.min.js
- Minified web browser<script src=>
compatible version.hljs-cedar.mjs
- ECMAScript module version with default export. Used bytest/cedar-esm.test.js
test cases andtest\vite\main.js
from Vite web app.import hljsCedar from '../dist/hljs-cedar.mjs';
hljs-cedar.cjs
- CommonJS module version with default export. Used bytest/cedar-commonjs.test.js
test cases.const hljsCedar = require('../dist/hljs-cedar.cjs').default;
npm run test
uses vitest to syntax highlight test/data/*.cedar
and test/data/*.cedarschema
files and compares against a generated .html
File Snapshots for each Cedar and Cedar human-readable schema file.
View either the static test/static/index.html
on your browser or npm run dev
and test/vite/index.html
renders in your browser: http://localhost:5173/
When new test/data/*.cedar
or test/data/*.cedarschema
files are created, npm run testdata
will update the contents of each index.html
file.
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.