emdash-plugin-highlightjs
v1.0.2
Published
Syntax highlighting for EmDash CMS using Highlight.js — 12 themes, auto dark/light mode, copy button, and a custom code block component for Portable Text.
Downloads
416
Maintainers
Readme
emdash-plugin-highlightjs
Syntax highlighting for EmDash CMS using Highlight.js. Features 12 themes, auto dark/light switching, a copy button, and a custom Portable Text code block component.
Features
- 12 themes — GitHub, Atom One, VS Code, A11Y, Stack Overflow, Tokyo Night, Rose Pine, Panda, Monokai, Dracula, Nord, Night Owl
- Auto dark/light — Themes with both variants switch via
MutationObserveron<html>class - Copy button — Optional floating copy button with "Copied!" feedback
- Portable Text block —
Code.astrocomponent with language detection and filename support - Admin settings — Theme picker and copy button toggle at
/_emdash/admin - CSS caching — Theme CSS read once and cached in memory
- Server-side highlighting — No client JS cost for syntax highlighting
Installation
npm install emdash-plugin-highlightjsUsage
Register the plugin in astro.config.mjs:
import { highlightjsPlugin } from "emdash-plugin-highlightjs";
export default defineConfig({
integrations: [
emdash({
plugins: [highlightjsPlugin()],
}),
],
});CSS and copy button are injected automatically on all public pages. Code.astro renders automatically for code blocks in Portable Text content.
How It Works
The plugin injects four fragments via the page:fragments hook:
- Light CSS (
<style id="hljs-l">) in<head> - Dark CSS (
<style id="hljs-d" disabled>) in<head> - Theme toggle script in
<head>—MutationObserveron<html>.class - Copy button script at
<body:end>
The Code.astro component renders code server-side via highlight.js — no client-side highlighting overhead.
Admin Settings
Navigate to /_emdash/admin → Highlight.js.
| Field | Default | Description |
|---|---|---|
| Syntax Theme | github | Pick from 12 themes |
| Show copy button | true | Toggle floating copy button |
Themes
| Theme | Dark variant | Light variant |
|---|---|---|
| GitHub | github-dark | github |
| Atom One | atom-one-dark | atom-one-light |
| VS Code | vs2015 | vs |
| A11Y | a11y-dark | a11y-light |
| Stack Overflow | stackoverflow-dark | stackoverflow-light |
| Tokyo Night | tokyo-night-dark | tokyo-night-light |
| Rose Pine | rose-pine | rose-pine-dawn |
| Panda | panda-syntax-dark | panda-syntax-light |
| Monokai | monokai | — |
| Dracula | dracula | — |
| Nord | nord | — |
| Night Owl | night-owl | — |
Themes with both variants switch automatically with your site's dark/light mode. Single-variant themes use the dark CSS only.
Development
git clone https://github.com/adrianoamalfi/emdash-plugin-highlightjs.git
cd emdash-plugin-highlightjs
npm install
npm run typecheck
npm testVersioning
This project follows Semantic Versioning. Releases are automated via semantic-release — pushing fix:, feat:, or BREAKING CHANGE: commits to main triggers a release to npm and GitHub.
License
MIT © Adriano Amalfi
