Skip to content
 
 

Repository files navigation

Markdansi 🎨 — Markdown, dressed for the terminal.

CI npm Node.js License

Markdansi rendering Markdown in a terminal

Markdansi renders GitHub Flavored Markdown as wrapped ANSI output for Node.js terminals. Use it as a CLI, an ESM library, or an append-only streamer for incremental output.

Install

Markdansi requires Node.js 22 or newer. Run the CLI without installing it:

npx markdansi README.md

Add the CLI and library to a project with your package manager:

npm install markdansi

Quick start

Pipe Markdown to the CLI and it writes rendered output to stdout:

$ printf '# Hello, **terminal**\n\n- wraps Markdown\n- formats tables\n' | npx markdansi --no-color --width 50

Hello, terminal
- wraps Markdown
- formats tables

Omit --no-color for ANSI styles and OSC-8 links when the terminal supports them.

Releasing the fork

Run releases only from a clean main branch:

pnpm release -- patch

The release command updates package.json and CHANGELOG.md, runs the complete pnpm build quality gate, commits release: vX.Y.Z, creates the tag, and pushes main plus the tag. The tag triggers npm OIDC publishing. Explicit versions and major / minor are also supported.

Use as a library

import { render } from "markdansi";

const output = render("# Hello **terminal**", { width: 60 });
process.stdout.write(output);

Markdansi ships as ESM. CommonJS callers can load it with import("markdansi").

createRenderer() binds options for repeated renders, while strip() produces plain text without ANSI or hyperlinks:

import { createRenderer, strip } from "markdansi";

const renderNarrow = createRenderer({ width: 48, theme: "dim" });
console.log(renderNarrow("## Status\n\nEverything is **ready**."));
console.log(strip("Read [the docs](https://example.com)."));

Stream incremental Markdown

createMarkdownStreamer() emits completed fragments without cursor movement or in-place redraw. Regular lines are emitted as they arrive; fenced code blocks and tables are buffered until they are complete.

import { createMarkdownStreamer, render } from "markdansi";

const streamer = createMarkdownStreamer({
  render: (markdown) => render(markdown, { width: process.stdout.columns ?? 80 }),
  spacing: "single",
});

process.stdin.setEncoding("utf8");
process.stdin.on("data", (chunk) => process.stdout.write(streamer.push(chunk)));
process.stdin.on("end", () => process.stdout.write(streamer.finish()));

This mode is intended for append-only output such as streamed model responses and terminal logs.

Customize rendering

Built-in themes are default, dim, bright, solarized, monochrome, and contrast. A custom theme can set named, hex, or ANSI-256 foreground and background colors.

Area Main options
Layout width, wrap, listIndent, quotePrefix
Color and links color, hyperlinks, theme
Tables tableBorder, tablePadding, tableDense, tableTruncate, tableEllipsis
Code blocks codeBox, codeGutter, codeWrap, highlighter

Markdansi does not bundle a syntax highlighter. Pass a highlighter(code, language) hook when you need one; see Syntax highlighting for a Shiki integration.

CLI and behavior reference

The CLI accepts Markdown from a positional file, --in, or stdin, and writes to stdout unless --out is set. See the CLI reference for every flag and the library reference for exports, options, rendering behavior, and edge cases.

Related

Looking for a native Swift implementation? See Swiftdansi.

Development

The build runs formatting, linting, type checking, tests, and compilation:

pnpm install --frozen-lockfile
pnpm build

License

MIT

About

Markdown to ANSII in TypeScript based on Micro-Mark, with support for URLs, tables, lists and more.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages