https://github.com/speed-highlight/core
A lightweight syntax highlighter written in JavaScript
https://github.com/speed-highlight/core
deno fast highlighter highlighting highlightjs javascript js language lightweight regex simple small syntax-highlighting ts
Last synced: 19 days ago
JSON representation
A lightweight syntax highlighter written in JavaScript
- Host: GitHub
- URL: https://github.com/speed-highlight/core
- Owner: speed-highlight
- License: cc0-1.0
- Created: 2021-08-14T12:18:55.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-06-03T17:11:19.000Z (5 months ago)
- Last Synced: 2025-10-03T14:41:06.899Z (about 1 month ago)
- Topics: deno, fast, highlighter, highlighting, highlightjs, javascript, js, language, lightweight, regex, simple, small, syntax-highlighting, ts
- Language: JavaScript
- Homepage: https://speed-highlight.github.io/core/examples/
- Size: 2.3 MB
- Stars: 349
- Watchers: 2
- Forks: 19
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- my-awesome-list - core - highlight | 353 | (JavaScript)
README
# Speed Highlight JS

- ๐ชถ Lightweight (**~2kB** for the core + **~1kB** by language)
- โก Fast (faster than prism and highlight.js on average)
- ๐งน Minimal Codebase
## Simple setup ๐
### Web
Style/theme (in the header of your html file):
```html
```
In the body of your html file:
```html
[code]
or
[inline code]
```
Highlight the code (in your javascript):
```js
import { highlightAll } from '/path/dist/index.js';
highlightAll();
```
Auto language detection
```js
import { highlightElement } from '../dist/index.js';
import { detectLanguage } from '../dist/detect.js';
elm.textContent = code;
highlightElement(elm, detectLanguage(code));
```
Load custom language
```js
import { loadLanguage } from '../dist/index.js';
loadLanguage('language-name', customLanguage);
```
---
#### CDN
```html
```
```js
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](https://deno.land/x/speed_highlight_js)
```js
import { setTheme, printHighlight } from 'https://deno.land/x/speed_highlight_js/dist/terminal.js';
await setTheme('[theme-name]');
printHighlight('console.log("hello")', 'js');
```
---
### Node
Use the [npm package](https://www.npmjs.com/package/@speed-highlight/core)
```bash
npm i @speed-highlight/core
```
```js
const { setTheme, printHighlight } = require('@speed-highlight/core/terminal');
setTheme('[theme-name]');
printHighlight('console.log("hello")', 'js');
```
## Migrating from prism
Speed-highlight JS is a lighter and faster version of prism that share a similar API
### Style
Remove the prism stylesheet in the head of your html file
Clone this repository or use a cdn to load our stylesheet
```diff
-
+
```
### Script
For the script part remove the prism.js script and replace it by a import and a call to `highlightAll`
```diff
-
+
+ import { highlightAll } from 'https://unpkg.com/@speed-highlight/core/dist/index.js';
+ highlightAll();
+
```
If you want to highlight only a specific element you can use the `highlightElement` function instead
### Code block
For the code blocks replace the `
` by only one ``
And use `shj-lang-` prefix instead of `language-` for the class property
```diff
-
p { color: red }
+p { color: red }
```
And for inline code block you just have to change the class property
```diff
-p { color: red }
+p { color: red }
```
## Languages supported ๐
| Name | Class name | Support | Language detection |
| ---------- | ------------------- | --------------------------------------------------- | ------------------ |
| asm | shj-lang-asm | | โ
|
| bash | shj-lang-bash | | โ
|
| brainfuck | shj-lang-bf | increment, operator, print, comment | โ |
| c | shj-lang-c | | โ
|
| css | shj-lang-css | comment, str, selector, units, function, ... | โ
|
| csv | shj-lang-csv | punctuation, ... | โ |
| diff | shj-lang-diff | | โ
|
| docker | shj-lang-docker | | โ
|
| git | shj-lang-git | comment, insert, deleted, string, ... | โ |
| go | shj-lang-go | | โ
|
| html | shj-lang-html | | โ
|
| http | shj-lang-http | keywork, string, punctuation, variable, version | โ
|
| ini | shj-lang-ini | | โ |
| java | shj-lang-java | | โ
|
| 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, ... | โ |
| rust | shj-lang-rs | | โ
|
| 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 | | โ
|
| xml | shj-lang-xml | | โ
|
| yaml | shj-lang-yaml | comment, numbers, variable, string, bool | โ |
## Themes ๐
A modern theme by default
| Name | Terminal | Web |
| ------------------- | -------- | --- |
| default | โ
| โ
|
| github-dark | โ | โ
|
| github-light | โ | โ
|
| github-dim | โ | โ
|
| atom-dark | โ
| โ
|
| visual-studio-dark | โ | โ
|