@diplodoc/color-extension

中文文档
1.0.0发布于 2026/08/06MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 2万

Inline color plugin for Diplodoc transformer and builder

原始使用文档
文档目录8 节
  1. Install
  2. Quick start
  3. Syntax
  4. API
  5. Options
  6. Example: custom class and inline style
  7. Example: escape parentheses
  8. Development

english | русский


NPM version Quality Gate Status Coverage Maintainability Rating Reliability Rating Security Rating

@diplodoc/color-extension

Inline color plugin for Diplodoc and markdown-it. Renders {colorName}(text) as styled spans (e.g. for semantic or custom colors).

Install

npm install @diplodoc/color-extension

Peer dependency: markdown-it ^13.0.0.

Quick start

const MarkdownIt = require('markdown-it');
const colorPlugin = require('@diplodoc/color-extension');

const md = new MarkdownIt().use(colorPlugin);

md.renderInline('{green}(hello)');
// => '<span class="yfm-colorify yfm-colorify--green">hello</span>'

With ESM:

import MarkdownIt from 'markdown-it';
import colorPlugin from '@diplodoc/color-extension';

const md = new MarkdownIt().use(colorPlugin);
md.renderInline('{primary}(sample)');

Syntax

  • Pattern: {colorName}(content)
  • Color name: any valid CSS color (e.g. red, #f00, rgb(255,0,0)) or semantic names like primary, green.
  • Nested colors: {green}(some {blue}(nested) text).

Examples:

InputOutput (default)
{green}(hello)<span class="yfm-colorify yfm-colorify--green">hello</span>
{red}(alert)<span class="yfm-colorify yfm-colorify--red">alert</span>
{green}(a {blue}(b) a)green span containing «a », blue span «b», green span « a»

API

Use the plugin with optional settings:

const md = new MarkdownIt().use(colorPlugin, {
  defaultClassName: 'yfm-colorify', // base class; modifier is `${defaultClassName}--${colorName}`
  inline: false, // if true, add inline style="color: ${colorName};"
  escape: false, // if true, allow \ to escape parentheses inside content
});

Options

OptionDefaultDescription
defaultClassName'yfm-colorify'Base CSS class; modifier --${colorName} is added.
inlinefalseWhen true, add style="color: ${colorName};" to the span.
escapefalseWhen true, backslash escapes parentheses inside (content) so literal ( and ) can be used.

Example: custom class and inline style

const md = new MarkdownIt().use(colorPlugin, {
  defaultClassName: 'my-color',
  inline: true,
});

md.renderInline('{red}(sample)');
// => '<span class="my-color my-color--red" style="color: red;">sample</span>'

Example: escape parentheses

With escape: true, \( and \) inside the content are rendered as literal ( and ):

const md = new MarkdownIt().use(colorPlugin, {escape: true});
md.renderInline('{green}(some(2,3))'); // => green span with "some(2,3)"
md.renderInline('{green}(some\\(2,3\\))'); // => green span with "some(2,3)"

Development

  • Build: npm run build
  • Tests: npm test (Vitest), npm run test:watch, npm run test:coverage
  • Lint: npm run lint, npm run lint:fix
  • Type check: npm run typecheck

版本与发布记录

@diplodoc/color-extension 共发布 3 个版本,首次发布于 2025/05/22;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0latest2026/08/063 个月前
0.1.12025/05/221.5 年前
0.1.02025/05/221.5 年前

关于 @diplodoc/color-extension 的常见问题

@diplodoc/color-extension 是什么?

Inline color plugin for Diplodoc transformer and builder

如何安装 @diplodoc/color-extension?

在项目目录运行 npm install @diplodoc/color-extension,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:markdown-it(^13.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@diplodoc/color-extension 支持 TypeScript 吗?

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

@diplodoc/color-extension 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@diplodoc/color-extension 可以商用吗?

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

@diplodoc/color-extension 的下载量有多少?

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

@diplodoc/color-extension 还在维护吗?

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