Code viewer · syntax highlighting

A dependency-free highlighter for JavaScript, TypeScript, JSX, Vue, HTML, CSS and shell — with titles, line numbers, highlighted lines and one-click copy.

Languages

JavaScriptcounter.js
import { signal, computed, html } from "@barisakin/zap"; // a counter: the text node reads the signal, nothing re-rendersexport function Counter({ start = 0 }) {  const count = signal(start);  const double = computed(() => count() * 2);  return html`<button class="zap-btn" onclick=${() => count.update((c) => c + 1)}>    Clicked ${count} times (×2 = ${double})  </button>`;}

Live — type, the highlight follows

JavaScript
const greet = (name) => `Hello, ${name}!`;console.log(greet("zap")); // try another language →

Without a header · wrapped

// the copy button shows on hover; long lines wrap instead of scrollingconst message = 'A long line of code that would otherwise scroll sideways goes on to the next line instead, because wrap is on for this block.';

Usage

JavaScript
import { signal } from "./index.js";import { CodeViewer, highlight } from "./components/code.js"; // js · jsx · ts · vue · html · css · sh · json — guessed when lang is left out.// html`…` templates are highlighted as HTML, their ${holes} as JavaScript.CodeViewer({  code: source,              // a string, or a signal / getter — re-highlights on change  lang: "js",  title: "counter.js",       // shown beside the language in the header  lineNumbers: true,  highlightLines: "4-5",     // or [4, 5]; startLine: 10 numbers from 10  maxHeight: 320,            // scrolls past this}) CodeViewer({ code, header: false, wrap: true })   // copy button on hover, soft wraphighlight(code, "css")                            // → an HTML string of .tk-* spans