Simple, light syntax highlighter for the web.
See the hosted demo
Get the library from NPM
npm install @kyleplo/elucidate
This library supports usage as both an ES6 module and a CommonJS module, as well as in the browser.
import elucidate from "@kyleplo/elucidate"
const elucidate = require("@kyleplo/elucidate");
<script src="https://gh.kyleplo.com/elucidate/bundle.min.js" defer></script>
Or host bundle.min.js
yourself.
Get syntax highlighting HTML
elucidate(`
alert("hello world");
`, "javascript");
// <span class=elucidate-default...
The language argument is optional, if ommitted a language-agnostic mode will be used.
The HTML includes 6 classes for various syntax features
elucidate-default
- basic contentelucidate-symbol
- symbolselucidate-keyword
- keywordselucidate-string
- stringselucidate-number
- numberselucidate-comment
- comment
CSS for these classes is not included
Elucidate supports the following programming languages
actionscript
- ActionScriptc
- Cc#
/cs
/csharp
- C#c++
/cpp
- C++coffeescript
- CoffeeScriptcss
- CSScsv
- CSVgolang
/go
- Golanghtml
/htm
- HTMLjava
- Javajavascript
/js
/jsx
- JavaScriptjson
- JSONlua
- Luamarkdown
/md
- Markdownphp
- PHPpython
/py
- Pythonruby
- Rubyscss
/sass
- SCSStsv
- TSVtypescript
/ts
- TypeScriptxml
- XMLyaml
/yml
- YAML
Languages are added in the languages.js
file and can be submitted via a pull request
Each language has the following properties
extend
- Another language string on the list for this language to inherit properties from - if omitted, inherits from thedefault
language - note that inherited arrays are not appended - the newer array replaces the old onestrings
- Array of strings that delimit stringsescape
- Array of strings that when placed before a string delimiter, cause the delimiter to be ignoredsymbols
- Array of strings used as symbols - case insensitivekeywords
- Array of strings used as keywords - case insensitive - will only be detected when surrounded by not-letter charactersmultiLineComment
- Array of two strings that mark the beginning and end of a segment to be ignored by the parser, or an empty arraysingleLineComment
- String placed at the beginning of a line causing the parser to ignore the remainder of the line