# marked-terminal

> A custom render for marked to output to the Terminal

Latest version **7.3.0** (published 2025-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install marked-terminal
pnpm add marked-terminal
yarn add marked-terminal
bun add marked-terminal
```

## Health

**Score 38/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.3.0 |
| Published | 2025-01-28 |
| First published | 2014-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/marked-terminal) |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 7 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 501 |
| Author | Mikael Brevik |
| Maintainers | mikaelb |
| Keywords | marked, render, terminal, markdown, markdown-to-terminal |

## Links

- npm: https://www.npmjs.com/package/marked-terminal
- Repository: https://github.com/mikaelbr/marked-terminal
- Issues: https://github.com/mikaelbr/marked-terminal/issues
- npm.io page: https://npm.io/package/marked-terminal

## Dependencies (7)

- [chalk](https://npm.io/package/chalk.md) ^5.4.1
- [ansi-regex](https://npm.io/package/ansi-regex.md) ^6.1.0
- [cli-table3](https://npm.io/package/cli-table3.md) ^0.6.5
- [node-emoji](https://npm.io/package/node-emoji.md) ^2.2.0
- [ansi-escapes](https://npm.io/package/ansi-escapes.md) ^7.0.0
- [cli-highlight](https://npm.io/package/cli-highlight.md) ^2.1.11
- [supports-hyperlinks](https://npm.io/package/supports-hyperlinks.md) ^3.1.0

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 7.3.0 (latest) — 2025-01-28
- 7.2.1 — 2024-10-30
- 7.2.0 — 2024-10-30
- 7.1.0 — 2024-06-14
- 7.0.0 — 2024-02-06
- 6.3.0 — 2024-02-06
- 6.2.0 — 2023-12-11
- 6.1.0 — 2023-11-13
- 6.0.0 — 2023-09-22
- 5.2.0 — 2023-05-11
- 5.1.1 — 2022-01-26
- 5.1.0 — 2022-01-26
- 5.0.0 — 2021-12-14
- 4.2.0 — 2021-09-16
- 4.1.1 — 2021-03-03
- … 22 more at https://npm.io/package/marked-terminal/versions

## README

# marked-terminal

> Custom Renderer for [marked](https://github.com/chjj/marked)
> allowing for printing Markdown to the Terminal. Supports pretty tables, syntax
> highlighting for javascript, and overriding all colors and styles.

Could for instance be used to print usage information.

[![build](https://github.com/mikaelbr/marked-terminal/actions/workflows/ci.yml/badge.svg)](https://github.com/mikaelbr/marked-terminal/actions/workflows/ci.yml) [![npm marked-terminal](https://img.shields.io/npm/v/marked-terminal.svg)](https://www.npmjs.com/package/marked-terminal)

## Install

```sh
npm install marked marked-terminal
```

## Example

```javascript
import { marked } from 'marked';
import { markedTerminal } from 'marked-terminal';

marked.use(markedTerminal([options][, highlightOptions]));

marked.parse('# Hello \n This is **markdown** printed in the `terminal`');
```

### Using older versions

```javascript
const marked = require('marked');
const TerminalRenderer = require('marked-terminal');

marked.setOptions({
  // Define custom renderer
  renderer: new TerminalRenderer()
});

// Show the parsed data
console.log(
  marked('# Hello \n This is **markdown** printed in the `terminal`')
);
```

This will produce the following:

![Screenshot of marked-terminal](./screenshot.png)

### Syntax Highlighting

Also have support for syntax highlighting using [cli-highlight](https://github.com/felixfbecker/cli-highlight).
You can override highlighting defaults by passing in settings as the second argument for TerminalRenderer.

Having the following markdown input:

<pre>
```js
var foo = function(bar) {
  console.log(bar);
};
foo('Hello');
```
</pre>

...we will convert it into terminal format:

```javascript
// Show the parsed data
console.log(marked(exampleSource));
```

This will produce the following:

![Screenshot of marked-terminal](./screenshot2.png)

## API

Constructur: `new TerminalRenderer([options][, highlightOptions])`

### `options`

Optional
Used to override default styling.

Default values are:

```javascript
var defaultOptions = {
  // Colors
  code: chalk.yellow,
  blockquote: chalk.gray.italic,
  html: chalk.gray,
  heading: chalk.green.bold,
  firstHeading: chalk.magenta.underline.bold,
  hr: chalk.reset,
  listitem: chalk.reset,
  table: chalk.reset,
  paragraph: chalk.reset,
  strong: chalk.bold,
  em: chalk.italic,
  codespan: chalk.yellow,
  del: chalk.dim.gray.strikethrough,
  link: chalk.blue,
  href: chalk.blue.underline,

  // Formats the bulletpoints and numbers for lists
  list: function (body, ordered) {/* ... */},

  // Reflow and print-out width
  width: 80, // only applicable when reflow is true
  reflowText: false,

  // Should it prefix headers?
  showSectionPrefix: true,

  // Whether or not to undo marked escaping
  // of enitities (" -> &quot; etc)
  unescape: true,

  // Whether or not to show emojis
  emoji: true,

  // Options passed to cli-table3
  tableOptions: {},

  // The size of tabs in number of spaces or as tab characters
  tab: 3 // examples: 4, 2, \t, \t\t

  image: function (href, title, text) {} // function for overriding the default image handling.
};
```

#### Example of overriding defaults

```javascript
marked.setOptions({
  renderer: new TerminalRenderer({
    codespan: chalk.underline.magenta
  })
});
```

### `highlightOptions`

Options passed into [cli-highlight](https://github.com/felixfbecker/cli-highlight). See readme there to see what options to pass.

See [more examples](./example/)

## Related

- [ink-markdown](https://github.com/cameronhunter/ink-markdown) - Markdown component for Ink

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