@comark/ansi
v0.7.0
Published
ANSI terminal renderer for Comark. Render Markdown with components as styled terminal output for CLIs.
Readme
@comark/ansi
ANSI terminal renderer for Comark. Render markdown as styled terminal output for CLIs, scripts, and developer tooling.
Features
- 🎨 ANSI-styled output for the terminal
- 🌈 Respects
NO_COLORautomatically - 📐 Configurable terminal width for HR and code blocks
- 🎯 Map any Comark tag to a custom render function
- 🔌 Plugin ecosystem (math, mermaid, highlight, binding…)
- 🎯 Full TypeScript support
Installation
npm install @comark/ansi
# or
pnpm add @comark/ansiUsage
import { renderAnsi } from '@comark/ansi'
const output = await renderAnsi(`
# Getting Started
This is a **bold** statement with a [link](https://example.com).
- Item 1
- Item 2
`)
process.stdout.write(output)Options
await renderAnsi(content, {
colors: true, // emit ANSI escape codes (defaults to true, false when NO_COLOR is set)
width: 80, // terminal width for HR and code block headers
plugins: [],
components: {},
})Syntax highlighting
import { renderAnsi } from '@comark/ansi'
import shiki from '@comark/ansi/plugins/shiki'
const output = await renderAnsi('```ts\nconsole.log("hi")\n```', {
plugins: [shiki()],
})API
renderAnsi(markdown, options?)parses and renders Markdown to an ANSI string.createAnsiRenderer(options?)creates a reusable parse-and-render function.renderAnsiFromDocument(document, options?)renders a pre-parsedMarkdownDocument.printAnsi(markdown, options?)parses and writes Markdown toprocess.stdoutor a customwriter. (writeAnsiis a deprecated alias.)createAnsiPrinter(options?)creates a reusable printer. (createAnsiWriteris a deprecated alias.)
import { createAnsiPrinter } from '@comark/ansi'
const printAnsi = createAnsiPrinter({
colors: false,
writer: (output) => process.stderr.write(output),
})
await printAnsi('# Build complete')Documentation
Full guide and API reference at comark.dev/rendering/ansi.
License
Made with ❤️
Published under MIT License.
