Light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection, try it out here
Blazing fast highlighting using regex
Style/theme (in the header of your html file):
<link rel="stylesheet" href="https://github.com/speed-highlight/core/blob/main/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));
Load custom language
import { loadLanguage } from '../src/index.js';
loadLanguage('language-name', customLanguage);
<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';
Use the deno module
import { setTheme, printHighlight } from 'https://x.nest.land/speed_highlight_js/dist/terminal.js';
await setTheme('[theme-name]');
printHighlight('console.log("hello")', 'js');
Use the npm package
npm i @speed-highlight/core
const { setTheme, printHighlight } = require('@speed-highlight/core/terminal');
setTheme('[theme-name]');
printHighlight('console.log("hello")', 'js');
Speed-highlight JS is a lighter and faster version of prism that share a similar API
Remove the prism stylesheet in the head of your html file Clone this repository or use a cdn to load our stylesheet
<head>
- <link href="https://github.com/speed-highlight/core/blob/main/themes/prism.css" rel="stylesheet" />
+ <link rel="stylesheet" href="https://unpkg.com/@speed-highlight/core/dist/themes/default.css">
</head>
For the script part remove the prism.js script and replace it by a import and a call to highlightAll
<body>
- <script src="https://github.com/speed-highlight/core/raw/main/prism.js"></script>
+<script>
+ import { highlightAll } from 'https://unpkg.com/@speed-highlight/core/dist/index.js';
+ highlightAll();
+</script>
</body>
If you want to highlight only a specific element you can use the highlightElement
function instead
For the code blocks replace the <pre><code>
by only one <div>
And use shj-lang-
prefix instead of language-
for the class property
-<pre><code class="language-css">p { color: red }</code></pre>
+<div class="shj-lang-css">p { color: red }</div>
And for inline code block you just have to change the class property
-<code class="language-css">p { color: red }</code>
+<code class="shj-lang-css">p { color: red }</code>
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 | โ |
A modern theme by default
Name | Terminal | Web |
---|---|---|
default | โ | โ |
github-dark | โ | โ |
github-light | โ | โ |
github-dim | โ | โ |
atom-dark | โ | โ |
visual-studio-dark | โ | โ |
Further in-depth documentation for the API and other topics is in our Wiki and our Documentation
Shj is released under the Creative Commons Zero License. See our LICENSE file for details.