Easy, efficient, and lightweight syntax highlighting.
npm:
npm i flashlight
Bun:
bun add flashlight
import { Flashlight } from "flashlightjs";
const flashlight = new Flashlight();
Note:
The default language is JavaScript, and the defult style is AtomDark.
import { Flashlight } from "flashlightjs";
import { Python } from "flashlightjs/languages";
const flashlight = new Flashlight([Python]);
import { Flashlight } from "flashlightjs";
import { AtomDark } from "flashlightjs/styles";
const flashlight = new Flashlight(undefined, AtomDark);
import { Flashlight } from "flashlightjs";
import { JavaScript } from "flashlightjs/languages";
import { AtomDark } from "flashlightjs/styles";
const code = `function greet(name) {
return "Hello, " + name + "!";
}`;
const flashlight = new Flashlight([JavaScript], AtomDark);
const highlightedCode = flashlight.highlight(code, "JavaScript");
import { Flashlight } from "flashlightjs";
import { JavaScript } from "flashlightjs/languages";
import { AtomDark, VSCode } from "flashlightjs/styles";
const code = `function greet(name) {
return "Hello, " + name + "!";
}`;
const flashlight = new Flashlight([JavaScript], AtomDark);
const highlightedCode = flashlight.highlight(code, "JavaScript", {
style: VSCode
});
import { Flashlight } from "flashlightjs";
import { Python } from "flashlightjs/languages";
import { AtomDark } from "flashlightjs/styles";
const code = `def greet(name):
return "Hello, " + name + "!"
`;
const flashlight = new Flashlight([Python], AtomDark);
const highlightedCode = flashlight.highlight(code, "Python");
Library | Time (ms) |
---|---|
flashlight 🔦 |
2.34 |
prismjs | 5.42 |
highlight.js | 14.05 |
These benchmarks show flashlight is approximately 6x faster than highlight.js and 2x faster than prismjs when highlighting equivalent code samples.
The main javascript syntax highlighting libraries (Prism, Highlight.js) are built using old standards, not readable, and generally take a less efficient approach to tokenizing code.
Flashlight aims to address these problems by doing the following:
- Use modern javascript/typescript standards.
- Create clean documentation for everything.
- Prioritize expressive syntax.
- Platform-independent code. Don't prioritize web over node.
- Use state-machine tokenization over regex pattern matching more info.
- [x] JavaScript
- [x] Python
- [x] HTML
- [ ] TypeScript
- [ ] CSS
- [ ] JSX
- [ ] TSX
- [ ] Rust