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.
Markdansi requires Node.js 22 or newer. Run the CLI without installing it:
npx markdansi README.mdAdd the CLI and library to a project with your package manager:
npm install markdansiPipe 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 tablesOmit --no-color for ANSI styles and OSC-8 links when the terminal supports them.
Run releases only from a clean main branch:
pnpm release -- patchThe 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.
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)."));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.
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.
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.
Looking for a native Swift implementation? See Swiftdansi.
The build runs formatting, linting, type checking, tests, and compilation:
pnpm install --frozen-lockfile
pnpm build