@comark/ansi

中文文档
0.9.0发布于 2026/11/06MITTypeScriptES Module构建来源已验证近 30 天下载 3875

ANSI terminal renderer for Comark. Render Markdown with components as styled terminal output for CLIs.

原始使用文档
文档目录8 节
  1. Features
  2. Installation
  3. Usage
  4. Options
  5. Syntax highlighting
  6. API
  7. Documentation
  8. License
Comark banner

@comark/ansi

npm version npm downloads CI Documentation license

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_COLOR automatically
  • 📐 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/ansi

Usage

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-parsed MarkdownDocument.
  • printAnsi(markdown, options?) parses and writes Markdown to process.stdout or a custom writer. (writeAnsi is a deprecated alias.)
  • createAnsiPrinter(options?) creates a reusable printer. (createAnsiWriter is 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.

版本与发布记录

@comark/ansi 共发布 15 个版本,首次发布于 2026/03/24;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.9.0latest2026/11/063 天前
0.8.12026/10/2120 天前
0.8.02026/10/2120 天前
0.7.02026/09/101 个月前
0.6.22026/08/073 个月前
0.6.12026/08/063 个月前

关于 @comark/ansi 的常见问题

@comark/ansi 是什么?

ANSI terminal renderer for Comark. Render Markdown with components as styled terminal output for CLIs.

如何安装 @comark/ansi?

在项目目录运行 npm install @comark/ansi,或使用 pnpm add / yarn add / bun add。

@comark/ansi 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@comark/ansi 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@comark/ansi 可以商用吗?

@comark/ansi 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@comark/ansi 的下载量有多少?

根据 npm 官方下载统计,@comark/ansi 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,875 次,日均约 129 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@comark/ansi 还在维护吗?

最新版本 0.9.0 发布于 2026/11/06(3 天前);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/03/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。