# markdown-or-chalk

> Prints through a single interface as Chalk enhanced CLI output or as Markdown

Latest version **0.3.2** (published 2026-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install markdown-or-chalk
pnpm add markdown-or-chalk
yarn add markdown-or-chalk
bun add markdown-or-chalk
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2026-07-27 |
| First published | 2023-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^22.13.0 \|\| >=24 |
| Dependencies | 10 |
| Unpacked size | 37.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 8 |
| Author | Pelle Wessman |
| Maintainers | voxpelli |
| Keywords | markdown, chalk, terminal, formatting, mdast, cli, ansi |

## Links

- npm: https://www.npmjs.com/package/markdown-or-chalk
- Repository: https://github.com/voxpelli/markdown-or-chalk
- Issues: https://github.com/voxpelli/markdown-or-chalk/issues
- npm.io page: https://npm.io/package/markdown-or-chalk

## Dependencies (10)

- [boxen](https://npm.io/package/boxen.md) ^8.0.1
- [chalk](https://npm.io/package/chalk.md) ^6.0.0
- [strip-ansi](https://npm.io/package/strip-ansi.md) ^7.1.0
- [@types/mdast](https://npm.io/package/@types/mdast.md) ^4.0.3
- [cli-highlight](https://npm.io/package/cli-highlight.md) ^2.1.11
- [terminal-link](https://npm.io/package/terminal-link.md) ^5.0.0
- [is-unicode-supported](https://npm.io/package/is-unicode-supported.md) ^2.0.0
- [mdast-util-gfm-table](https://npm.io/package/mdast-util-gfm-table.md) ^2.0.0
- [mdast-util-to-string](https://npm.io/package/mdast-util-to-string.md) ^4.0.0
- [mdast-util-to-markdown](https://npm.io/package/mdast-util-to-markdown.md) ^2.1.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2026-07-27
- 0.3.1 — 2026-07-27
- 0.3.0 — 2026-07-27
- 0.2.3 — 2024-09-12
- 0.2.2 — 2024-09-09
- 0.2.1 — 2024-06-25
- 0.2.0 — 2023-10-29
- 0.1.2 — 2023-07-20
- 0.1.1 — 2023-07-20
- 0.1.0 — 2023-07-20

## README

# Markdown or Chalk

Print through a single interface as Markdown or terminal output (`ansi` / `chalk`).

[![npm version](https://img.shields.io/npm/v/markdown-or-chalk.svg?style=flat)](https://www.npmjs.com/package/markdown-or-chalk)
[![npm downloads](https://img.shields.io/npm/dm/markdown-or-chalk.svg?style=flat)](https://www.npmjs.com/package/markdown-or-chalk)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-7fffff?style=flat\&labelColor=ff80ff)](https://github.com/neostandard/neostandard)
[![Module type: ESM](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
[![Types in JS](https://img.shields.io/badge/types_in_js-yes-brightgreen)](https://github.com/voxpelli/types-in-js)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/voxpelli/markdown-or-chalk)

## Usage

The core idea: keep your formatting calls the same, and decide output style at runtime.

```javascript
import { getOutputStyler } from 'markdown-or-chalk';

const printAsMarkdown = true;

const format = getOutputStyler(printAsMarkdown);

format.header('Wow');
```

This lets one code path support terminal UX and markdown/report output.

## API

### `getOutputStyler(style)`

Returns a formatter for one of these styles:

* `'markdown'` – Markdown output
* `'ansi'` – ANSI terminal output
* `'chalk'` – Chalk-flavored terminal output (legacy compatibility; prefer `'ansi'`)

### `getMdastOutputter(style)`

Returns only the `fromMdast` renderer function for the selected style.

### Instance Methods

| Method                           | Description                                                                                                                          |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `header(text, level?)`           | Heading (1-6, default 1). Markdown: `# text`. Terminal: bold+underline                                                               |
| `bold(text)`                     | Bold. Markdown: `**text**`. Terminal: bold                                                                                           |
| `dim(text)`                      | Dim/italic. Markdown: `_text_`. Terminal: dim                                                                                        |
| `italic(text)`                   | Italic. Markdown: `_text_`. Terminal: italic                                                                                         |
| `strikethrough(text)`            | Strikethrough. Markdown: `~~text~~`. Terminal: strikethrough                                                                         |
| `code(text)`                     | Inline code. Markdown: `` `text` ``. Terminal: plain text                                                                            |
| `hyperlink(text, url, options?)` | Link. Markdown: `[text](url)` (options ignored). Terminal: terminal link. Options: `{ fallback?: boolean, fallbackToUrl?: boolean }` |
| `list(items)`                    | Bullet list. Markdown: `* item`. Terminal: `- item`                                                                                  |
| `indent(text, level?)`           | Indent by level × 2 spaces (default level is 1)                                                                                      |
| `json(value)`                    | JSON output. Markdown: fenced code block. Terminal: plain JSON                                                                       |
| `table(rows, align?, options?)`  | Table. Markdown: GFM table (supports `{ tablePipeAlign?: boolean }`). Terminal: aligned columns                                      |
| `fromMdast(node, options?)`      | Render any mdast node to string                                                                                                      |

### Getters

| Getter            | Returns                                                       |
| ----------------- | ------------------------------------------------------------- |
| `type`            | `'markdown'`, `'ansi'`, or `'chalk'`                          |
| `logSymbols`      | `{info, success, warning, error}` — emoji or styled symbols   |
| `logSymbolsMdast` | `{info, success, warning, error}` — mdast-compatible symbols  |
| `chalk`           | `ChalkInstance` in chalk mode (`deprecated`, prefer `'ansi'`) |

### Exported Helpers

| Helper                                 | Description                      |
| -------------------------------------- | -------------------------------- |
| `mdastTableHelper(rows, align?)`       | Build an mdast Table node        |
| `mdastListHelper(items)`               | Build an mdast List node         |
| `mdastLinkify(value, url, skipLinks?)` | Build an mdast Link or Text node |

### Advanced: mdast helpers

Compose `fromMdast` with the mdast helpers to build rich structured output:

```javascript
import { getMdastOutputter, mdastListHelper, mdastLinkify } from 'markdown-or-chalk';

const fromMdast = getMdastOutputter('markdown');

const list = mdastListHelper([
  [mdastLinkify('chalk', 'https://www.npmjs.com/package/chalk')],
  [mdastLinkify('mdast', 'https://www.npmjs.com/package/mdast')],
  ['plain text item'],
]);

console.log(fromMdast(list));
// * [chalk](https://www.npmjs.com/package/chalk)
// * [mdast](https://www.npmjs.com/package/mdast)
// * plain text item
```

## Migration: 0.2.x → 0.3.x

### What changed

* Constructor-based usage was replaced with a selector function:
  * `getOutputStyler('markdown' | 'ansi' | 'chalk')`
* `getMdastOutputter('markdown' | 'ansi' | 'chalk')` was added as a convenience for mdast-only flows.
  * Existing `getOutputStyler(style).fromMdast(node)` usage still works.
* Style is now selected using explicit string modes (`'markdown'`, `'ansi'`, `'chalk'`).
* `type` is the mode discriminator.
* `chalk` getter is legacy (`deprecated`) and only relevant in `'chalk'` mode (prefer `'ansi'`).

### Before / after

```javascript
// Before (0.2.x)
import MarkdownOrChalk from 'markdown-or-chalk';

const formatMd = new MarkdownOrChalk(true);
const formatCli = new MarkdownOrChalk(false);
```

```javascript
// After (0.3.x)
import { getOutputStyler } from 'markdown-or-chalk';

const formatMd = getOutputStyler('markdown');
const formatCli = getOutputStyler('ansi');
```

```javascript
// After (0.3.x), mdast-only outputter
import { getMdastOutputter } from 'markdown-or-chalk';

const fromMdast = getMdastOutputter('markdown');
const output = fromMdast(node);
```

### Migration checklist

* Replace constructor usage with `getOutputStyler()` / `getMdastOutputter()`.
* Replace boolean mode selection with explicit style strings.
* If branching by mode, check `.type`.
* Keep `.chalk` usage only for legacy paths.
* Re-check output-sensitive behavior:
  * `hyperlink()` in markdown mode
  * `list()` formatting
  * `table()` formatting

## Used by

* [`@voxpelli/pretty-ts-errors-cli`](https://github.com/voxpelli/pretty-ts-errors-cli)
* [`compare-eslint-configs`](https://github.com/voxpelli/compare-eslint-configs)

## See also

* [`chalk`](https://www.npmjs.com/package/chalk)
* [`mdast`](https://www.npmjs.com/package/mdast)
* [`mdast-util-to-markdown`](https://www.npmjs.com/package/mdast-util-to-markdown)

---
_Source: https://npm.io/package/markdown-or-chalk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
