1.1.7
π Light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection
Repository
Current version released
3 years ago
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 β‘
Blazing fast highlighting using regex
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
<link rel="stylesheet" href="https://unpkg.com/@speed-highlight/core/dist/themes/default.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/speed-highlight/core/dist/themes/default.css">
import ... from 'https://unpkg.com/@speed-highlight/core/dist/index.js'
import ... from 'https://cdn.jsdelivr.net/gh/speed-highlight/core/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 i @speed-highlight/core
const { setTheme, printHighlight } = require('@speed-highlight/core/dist/node/term.js');
setTheme('default')
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.