npm package: @indiekitai/glamour
Description: Stylesheet-based markdown rendering for terminals - port of charmbracelet/glamour
Latest version: 0.1.0

# @indiekitai/glamour

Stylesheet-based markdown rendering for terminals. A TypeScript port of [charmbracelet/glamour](https://github.com/charmbracelet/glamour).

## Features

- 🎨 **Built-in themes** — Dark, Light, ASCII, Pink, Dracula, Tokyo Night, NoTTY
- 📝 **Markdown rendering** — Headings, bold, italic, code, lists, tables, links, images, blockquotes
- 📏 **Word wrapping** — Automatic word wrap to terminal width
- 🎭 **Custom styles** — Full stylesheet-based customization via JSON or objects
- 🔧 **MCP Server** — Model Context Protocol integration
- 🖥️ **CLI** — `npx @indiekitai/glamour README.md`
- 📦 **Zero native deps** — Pure TypeScript, uses `marked` for parsing

## Installation

```bash
npm install @indiekitai/glamour
```

## Quick Start

```typescript
import { render } from '@indiekitai/glamour';

// Render with auto-detected style
console.log(render('# Hello World\n\nThis is **glamour**!'));

// Render with a specific style
console.log(render('# Hello', 'dark'));
console.log(render('# Hello', 'dracula'));
console.log(render('# Hello', 'ascii'));
```

## API

### `render(markdown, style?)`

Quick render function. Style can be a name (`'dark'`, `'light'`, `'ascii'`, etc.) or a `StyleConfig` object.

```typescript
import { render } from '@indiekitai/glamour';
console.log(render('**bold** and *italic*', 'dark'));
```

### `new TermRenderer(options?)`

Create a reusable renderer with full configuration.

```typescript
import { TermRenderer } from '@indiekitai/glamour';

const renderer = new TermRenderer({
  style: 'dark',      // or 'light', 'ascii', 'pink', 'dracula', 'tokyo-night', StyleConfig
  wordWrap: 100,       // default: 80
  baseURL: 'https://github.com/user/repo',
  preserveNewLines: true,
});

console.log(renderer.render('# Title\n\nBody text'));
```

### `renderWithEnvironmentConfig(markdown)`

Renders using the `GLAMOUR_STYLE` environment variable (falls back to `'auto'`).

```typescript
import { renderWithEnvironmentConfig } from '@indiekitai/glamour';
// Set GLAMOUR_STYLE=dark in your environment
console.log(renderWithEnvironmentConfig('# Hello'));
```

## Built-in Styles

| Style | Description |
|-------|-------------|
| `auto` | Auto-detect (dark if TTY, notty otherwise) |
| `dark` | Dark terminal theme with colors |
| `light` | Light terminal theme |
| `ascii` | ASCII-only, no ANSI colors |
| `notty` | For non-TTY output (same as ascii) |
| `pink` | Pink accent theme |
| `dracula` | Dracula color scheme |
| `tokyo-night` | Tokyo Night color scheme |

## Custom Styles

```typescript
import { TermRenderer, type StyleConfig } from '@indiekitai/glamour';

const myStyle: StyleConfig = {
  document: { margin: 4, color: '#FFFFFF' },
  heading: { bold: true, color: '#FF6B6B', blockSuffix: '\n' },
  h1: { prefix: '🚀 ' },
  strong: { bold: true, color: '#FFD700' },
  code: { prefix: ' ', suffix: ' ', color: '#50FA7B', backgroundColor: '#282A36' },
  link: { color: '#8BE9FD', underline: true },
};

const r = new TermRenderer({ style: myStyle });
console.log(r.render('# My Doc\n\n**Important** info'));
```

## CLI

```bash
# Render a file
npx @indiekitai/glamour README.md

# Pipe from stdin
cat README.md | npx @indiekitai/glamour

# Choose a style
npx @indiekitai/glamour --style dracula README.md

# Set width
npx @indiekitai/glamour --width 60 README.md

# JSON output
npx @indiekitai/glamour --json README.md
```

## MCP Server

Start the MCP server for AI agent integration:

```bash
node dist/mcp.js
```

Available tools:
- `render_markdown` — Render markdown with a chosen style
- `render_plain` — Render with ASCII-only style
- `list_styles` — List available styles

## Utilities

```typescript
import { stripAnsi, visibleWidth, wordwrap, indentText, padText } from '@indiekitai/glamour';

stripAnsi('\x1b[1mBold\x1b[0m');  // 'Bold'
visibleWidth('\x1b[1mHello\x1b[0m');  // 5
wordwrap('long text here', 10);
indentText('line1\nline2', 2);  // '  line1\n  line2'
```

## License

MIT

## Credits

TypeScript port of [charmbracelet/glamour](https://github.com/charmbracelet/glamour) by [IndieKit AI](https://github.com/indiekitai).