Registration

Languages must be registered by the RyuseiLight.register() static function before highlighting code. Each language is a function that returns a Language object:

import { RyuseiLight, json } from '@ryusei/light';
RyuseiLight.register( json() );
JavaScript

The method accepts an array for multiple languages:

import { RyuseiLight, json, typescript } from '@ryusei/light';
RyuseiLight.register( [ json(), typescript() ] );
JavaScript

Default Language

The RyuseiLight class takes default options through the constructor. The apply() and html() member methods respect the defaults.

const ryuseilight = new RyuseiLight( { language: 'jsx' } );
// Highlights elements by JSX.
ryuseilight.apply( '.jsx-code' );
// Generates HTML by JSX.
const html = ryuseilight.html( '<div>message</div>' );
JavaScript

The default options can be overwritten by local options:

ryuseilight.apply( '.json-code', { language: 'json' } );
const html = ryuseilight.html( '{ title: "Ryusei" }', { language: 'json' } );
JavaScript

Data Attribute

If a page contains some code snippets in different languages, it may be hard to apply each language to each element. By using the data-rl-language data attribute, the language can be specified from HTML.

<pre data-rl-language="js">
console.log( 'hello!' );
</pre>
<pre data-rl-language="css">
body { color: skyblue; }
</pre>
HTML
const ryuseilight = new RyuseiLight();
ryuseilight.apply( 'pre' );
JavaScript

Language List

Here is a list of languages that are currently available. Not many, but I will try to add more (slowly).

LanguageID/Alias
CSScss
HTMLhtml, markup
JavaScriptjavascript, js
JSONjson
JSXjsx, react
TSXtsx
NONEnone
SCSSscss
SVGsvg
TypeScripttypescript, ts
Vuevue
XMLxml