0.0.5 • Published 3 years ago
@kyleplo/elucidate v0.0.5
elucidate
Simple, light syntax highlighter for the web.
See the hosted demo
Installation
Get the library from NPM
npm install @kyleplo/elucidateImporting
This library supports usage as both an ES6 module and a CommonJS module, as well as in the browser.
ES6
import elucidate from "@kyleplo/elucidate"CommonJS
const elucidate = require("@kyleplo/elucidate");Browser
<script src="https://gh.kyleplo.com/elucidate/bundle.min.js" defer></script>Or host bundle.min.js yourself.
Usage
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
Language Support
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
Adding a Language
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 thedefaultlanguage - 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