lisp-highlight
v1.0.2
Published
Lightweight syntax highlighter for Lisp code in web applications
Maintainers
Readme
lisp-highlight
A minimal, lightweight syntax highlighter for Lisp code designed for web environments.
Features
- Highlights parentheses, keywords, strings, and numbers
- Lightweight and dependency-free
- Suitable for browser environments (ES Module)
- Optional automatic CSS injection
Installation
Using npm registry
npm install lisp-highlightUsing GitHub Packages
To use GitHub Packages, you need an .npmrc file in your project root directory.
Location of
.npmrc- Create the
.npmrcfile in your project root (wherepackage.jsonis located). - If you prefer a global configuration, you can create it in your home directory (
~/.npmrc).
- Create the
Example
.npmrccontent
@hwahyeon:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKENHow to generate a token
- Go to your GitHub account settings → Developer settings → Personal access tokens → "Tokens (classic)"
- The token must have at least
read:packagespermission. - Replace
YOUR_GITHUB_TOKENin the.npmrcfile with the generated token.
Install the package
npm install @hwahyeon/lisp-highlightNote: When using GitHub Packages, add
.npmrcto your.gitignorefile to prevent exposing your token publicly.
Usage
import { highlightLisp } from "./lisp-highlight.js"; // Adjust path as needed
const code = "(define (square x) (* x x))";
const html = highlightLisp(code);
document.getElementById("output").innerHTML = html;Styling Behavior
By default, CSS styles are automatically injected into the document:
highlightLisp(code); // Automatic styles appliedYou can disable this and provide your own styles:
highlightLisp(code, { injectStyles: false });In that case, define CSS manually:
<style>
.paren {
color: green;
}
.string {
color: orange;
}
.number {
color: purple;
font-weight: bold;
}
.keyword {
color: blue;
font-weight: bold;
text-decoration: underline;
}
</style>Or use an external CSS file:
<link rel="stylesheet" href="highlight.css" />Note: This library does not insert inline styles automatically. It generates <span> elements with class names (paren, string, number, keyword) which you can style as needed.
Supported Highlighting
()highlighted as parentheses"strings"string highlighting- Numbers like
123,3.14number highlighting - Keywords:
define,lambda,if,else,cond,let,begin
