npm package: @geepers/markdown
Description: Markdown renderer for LLM chat output — marked + highlight.js + optional KaTeX
Author: Luke Steuber
Latest version: 1.0.0
Deprecated: This package is no longer maintained. Use @geepers/chat instead.

# @geepers/markdown

[![npm](https://img.shields.io/npm/v/@geepers/markdown)](https://www.npmjs.com/package/@geepers/markdown)
[![license](https://img.shields.io/npm/l/@geepers/markdown)](./LICENSE)
[![types](https://img.shields.io/npm/types/@geepers/markdown)](./src/index.ts)

Markdown renderer built for LLM chat output. Wraps [marked](https://marked.js.org/) with sensible defaults for streaming chat: syntax-highlighted code blocks, sanitized links, tables, and optional KaTeX for math.

Works in the browser and returns a plain HTML string — no framework required.

---

## Install

```bash
npm install @geepers/markdown marked
```

### With syntax highlighting

```bash
npm install @geepers/markdown marked highlight.js
```

### With math rendering

```bash
npm install @geepers/markdown marked katex
```

---

## Quick start

```ts
import { renderLLMMarkdown } from '@geepers/markdown';

// Basic usage
document.querySelector('#response').innerHTML = renderLLMMarkdown(markdownText);

// With all options
document.querySelector('#response').innerHTML = renderLLMMarkdown(markdownText, {
  highlight: true,      // syntax highlight code blocks (needs highlight.js)
  tables: true,         // render GFM tables
  sanitizeLinks: true,  // force target="_blank", strip javascript: hrefs
  math: false,          // render LaTeX via KaTeX (needs katex)
  gfm: true,            // GitHub Flavored Markdown
  breaks: true,         // newlines → <br>
});
```

In a streaming chat UI you can call it on every chunk — it's synchronous and fast:

```ts
reader.on('chunk', (chunk) => {
  buffer += chunk;
  messageEl.innerHTML = renderLLMMarkdown(buffer);
});
```

---

## Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `highlight` | `boolean` | `true` | Syntax-highlight code blocks via highlight.js. Degrades gracefully if hljs isn't installed. |
| `tables` | `boolean` | `true` | Render GFM tables. |
| `sanitizeLinks` | `boolean` | `true` | Force `target="_blank"` + `rel="noopener noreferrer"` on all links, strip `javascript:` and `data:` hrefs. |
| `math` | `boolean` | `false` | Render `$...$` and `$$...$$` LaTeX via KaTeX. Requires katex peer dep. |
| `gfm` | `boolean` | `true` | GitHub Flavored Markdown (tables, strikethrough, task lists). |
| `breaks` | `boolean` | `true` | Convert single newlines to `<br>` — matches the soft-wrap behavior most chat UIs expect. |

---

## Peer dependencies

Both are optional. The renderer works without them — code blocks fall back to escaped plain text, math blocks are left as-is.

| Package | Version | What it enables |
|---------|---------|-----------------|
| `highlight.js` | `>=11.0.0` | Syntax highlighting in code blocks |
| `katex` | `>=0.16.0` | LaTeX math rendering (`$...$` and `$$...$$`) |

---

## SSR / Node.js

If you're running outside the browser, inject your instances explicitly instead of relying on `globalThis`:

```ts
import hljs from 'highlight.js';
import katex from 'katex';
import { setHighlighter, setKatex, renderLLMMarkdown } from '@geepers/markdown';

setHighlighter(hljs);
setKatex(katex);

const html = renderLLMMarkdown(text, { math: true });
```

---

## License

MIT — Luke Steuber