Skip to main content
Deno 2 is finally here πŸŽ‰οΈ
Learn more

Speed Highlight JS

Light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection, try it out here

Light πŸ“¦

  • The core is about 1kB (gzipped & minified)
  • Languages definition are from a few bytes to 1kB
  • Themes are about 1kB
  • Language rules needed are automatically loaded

Fast ⚑

Simple setup πŸš€

Web

Style/theme (in the header of your html file):

<link rel="stylesheet" href="/path/dist/themes/default.css">

In the body of your html file:

<div class='shj-lang-[code-language]'>[code]</div>
or
<code class='shj-lang-[code-language]'>[inline code]</code>

Highlight the code (in your javascript):

import { highlightAll } from '/path/dist/index.js'
highlightAll();

Auto language detection

import { highlightElement } from '../src/index.js';
import { detectLanguage } from '../src/detect.js';

elm.textContent = code;
highlightElement(elm, detectLanguage(code));

CDN

import ... from 'https://unpkg.com/speed_highlight_js/dist/index.js'
import ... from 'https://cdn.jsdelivr.net/gh/matubu/speed_highlight_js/dist/index.js'

Deno

Use the Deno module

import { setTheme, printHighlight } from 'https://x.nest.land/speed_highlight_js/dist/term.js';

await setTheme('default');
printHighlight('console.log("hello")', 'js');

Node

Use the npm package

npm install speed_highlight_js
const { setTheme, printHighlight } = require('speed_highlight_js/dist/node/term.js');

setTheme('default')
  .then(() => printHighlight('console.log("hello")', 'js'));

Languages supported 🌐

Name Class name Support Language detection
bash shj-lang-bash βœ…
brainfuck shj-lang-bf increment, operator, print, comment ❌
css shj-lang-css comment, str, selector, units, function, … βœ…
csv shj-lang-csv punctuation, … ❌
diff shj-lang-diff βœ…
git shj-lang-git comment, insert, deleted, string, … ❌
html shj-lang-html βœ…
http shj-lang-http keywork, string, punctuation, variable, version βœ…
ini shj-lang-ini ❌
javascipt shj-lang-js basic syntax, regex, jsdoc, json, template literals βœ…
jsdoc shj-lang-jsdoc ❌
json shj-lang-json string, number, bool, … ❌
leanpub-md shj-lang-leanpub-md ❌
log shj-lang-log number, string, comment, errors ❌
lua shj-lang-lua βœ…
makefile shj-lang-make βœ…
markdown shj-lang-md βœ…
perl shj-lang-pl βœ…
plain shj-lang-plain ❌
python shj-lang-py βœ…
regex shj-lang-regex count, set, … ❌
sql shj-lang-sql number, string, function, … βœ…
todo shj-lang-todo ❌
toml shj-lang-toml comment, table, string, bool, variable ❌
typescript shj-lang-ts js syntax, ts keyword, types βœ…
uri shj-lang-uri βœ…
yaml shj-lang-yaml comment, numbers, variable, string, bool ❌
docker shj-lang-docker βœ…
c shj-lang-c βœ…
xml shj-lang-xml βœ…
rust shj-lang-rs βœ…
go shj-lang-go βœ…
java shj-lang-java βœ…
asm shj-lang-asm βœ…

Themes 🌈

A modern theme by default

Name Terminal Web
default βœ… βœ…
github-dark ❌ βœ…
github-light ❌ βœ…
github-dim ❌ βœ…
atom-dark ❌ βœ…
visual-studio-dark ❌ βœ…

Wiki πŸ‘€

Further in-depth documentation for the API and other topics is in our Wiki

License πŸ“ƒ

Shj is released under the Creative Commons Zero License. See our LICENSE file for details.