@accordproject/markdown-common

中文文档
2.0.0发布于 2026/10/11Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 1.2万

A framework for transforming markdown

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. What this package exports
  4. License

CommonMark Transformer

Converts markdown text to/from a CommonMark DOM.

The CommonMark DOM is a Concerto model — see [email protected].

Installation

npm install @accordproject/markdown-common

Peer dependency: @accordproject/concerto-core@^5.0.0.

Usage

import { CommonMarkTransformer } from '@accordproject/markdown-common';

const transformer = new CommonMarkTransformer();
const dom = transformer.fromMarkdown('# Heading\n\nThis is some `code`.\n\nFin.');
console.log(JSON.stringify(dom, null, 4));

CommonJS works too:

const { CommonMarkTransformer } = require('@accordproject/markdown-common');

The output is:

{
    "$class": "[email protected]",
    "xmlns": "http://commonmark.org/xml/1.0",
    "nodes": [
        {
            "$class": "[email protected]",
            "level": "1",
            "nodes": [
                {
                    "$class": "[email protected]",
                    "text": "Heading"
                }
            ]
        },
        {
            "$class": "[email protected]",
            "nodes": [
                {
                    "$class": "[email protected]",
                    "text": "This is some "
                },
                {
                    "$class": "[email protected]",
                    "text": "code"
                },
                {
                    "$class": "[email protected]",
                    "text": "."
                }
            ]
        },
        {
            "$class": "[email protected]",
            "nodes": [
                {
                    "$class": "[email protected]",
                    "text": "Fin."
                }
            ]
        }
    ]
}

You can manipulate the DOM and convert it back to markdown:

dom.nodes[0].nodes[0].text = 'My New Heading';
const newMarkdown = transformer.toMarkdown(dom);
console.log(newMarkdown);

The new markdown string will be:

My New Heading
====

This is some `code`.

Fin.

Note how the H1 heading has been normalized during conversion from # syntax to ==== syntax. In CommonMark these are equivalent.

What this package exports

  • CommonMarkTransformer — markdown ↔ CommonMark DOM
  • ToMarkdownVisitor, FromCommonMarkVisitor, FromMarkdownIt — lower-level building blocks
  • CommonMarkUtils — helpers for rendering markdown (escaping, list prefixes, etc.)
  • Stack — generic stack used by the visitors
  • CommonMarkModel, CiceroMarkModel, ConcertoMetaModel, TemplateMarkModel — Concerto namespace/MODEL strings consumed by the other packages in this monorepo

License

Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.

版本与发布记录

@accordproject/markdown-common 共发布 1,033 个版本,首次发布于 2019/09/12;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.0latest2026/10/1125 天前
1.1.02026/09/141 个月前
1.0.12026/06/045 个月前
0.18.12026/05/195 个月前
0.18.02026/05/066 个月前
0.17.22026/02/268 个月前

其他发布通道:unstable → 0.16.20-20251210135052。

关于 @accordproject/markdown-common 的常见问题

@accordproject/markdown-common 是什么?

A framework for transforming markdown

如何安装 @accordproject/markdown-common?

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

@accordproject/markdown-common 支持 TypeScript 吗?

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

@accordproject/markdown-common 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@accordproject/markdown-common 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@accordproject/markdown-common 可以商用吗?

@accordproject/markdown-common 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@accordproject/markdown-common 的下载量有多少?

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

@accordproject/markdown-common 还在维护吗?

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