@accordproject/markdown-cli

中文文档
2.0.0发布于 2026/10/11Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 1706

A framework for transforming markdown

原始使用文档
文档目录9 节
  1. Usage
  2. markus transform
  3. Example
  4. --from and --to options
  5. --via option
  6. --roundtrip option
  7. --model and --contract options
  8. --extension option
  9. License

Command Line

Install the @accordproject/markdown-cli npm package to get the markus command line interface (CLI). After installation you can use the markus command and its sub-commands as described below.

To install:

npm install -g @accordproject/markdown-cli

Usage

markus is a command line tool to debug and use markdown transformations.

markus <cmd> [args]

Commands:
  markus transform  transform between two formats

Options:
  --version      Show version number                                   [boolean]
  --verbose, -v                                                 [default: false]
  --help         Show help                                             [boolean]

markus transform

The markus transform command lets you transform between any two of the supported formats.

markus transform

transform between two formats

Options:
  --version      Show version number                                   [boolean]
  --verbose, -v  verbose output                       [boolean] [default: false]
  --help         Show help                                             [boolean]
  --input        path to the input                                      [string]
  --from         source format                    [string] [default: "markdown"]
  --to           target format                  [string] [default: "commonmark"]
  --via          intermediate formats                      [array] [default: []]
  --roundtrip    roundtrip transform                  [boolean] [default: false]
  --output       path to the output file                                [string]
  --model        array of concerto model files                           [array]
  --template     template grammar                                       [string]
  --contract     contract template                    [boolean] [default: false]
  --currentTime  set current time                       [string] [default: null]
  --plugin       path to a parser plugin                                [string]
  --extension    path to a transform extension                           [array]
  --sourcePos    enable source position               [boolean] [default: false]
  --offline      do not resolve external models       [boolean] [default: false]

Supported formats for --from / --to / --via:

markdown, markdown_cicero, markdown_template, commonmark_tokens, ciceromark_tokens, templatemark_tokens, commonmark, ciceromark, ciceromark_parsed, ciceromark_unquoted, templatemark, ciceroedit, html, plaintext.

Example

Run transform on a markdown file:

markus transform --input README.md

returns:

{
  "$class": "[email protected]",
  "xmlns": "http://commonmark.org/xml/1.0",
  "nodes": [
    {
      "$class": "[email protected]",
      "level": "1",
      "nodes": [
        {
          "$class": "[email protected]",
          "text": "Hello World"
        }
      ]
    },
    {
      "$class": "[email protected]",
      "nodes": [
        {
          "$class": "[email protected]",
          "text": "This is the Hello World of Accord Project Templates. Executing the clause will simply echo back the text that occurs after the string "
        },
        {
          "$class": "[email protected]",
          "text": "Hello"
        },
        {
          "$class": "[email protected]",
          "text": " prepended to text that is passed in the request."
        }
      ]
    }
  ]
}

--from and --to options

Set the source and target formats. The following converts markdown to HTML:

markus transform --from markdown --to html --input README.md

returns:

<html>
<body>
<div class="document">
<h1>Hello World</h1>
<p>This is the Hello World of Accord Project Templates. Executing the clause will simply echo back the text that occurs after the string <code>Hello</code> prepended to text that is passed in the request.</p>
</div>
</body>
</html>

--via option

When there are several paths between two formats, you can route through an intermediate format. The following transforms from markdown to html via ciceromark:

markus transform --from markdown --via ciceromark --to html --input README.md

--roundtrip option

You can roundtrip between two formats — transform from source to target then back to source. For example, markdown → ciceromark → markdown:

markus transform --from markdown --to ciceromark --input README.md --roundtrip

returns:

Hello World
====

This is the Hello World of Accord Project Templates. Executing the clause will simply echo back the text that occurs after the string `Hello` prepended to text that is passed in the request.

Roundtripping might result in small textual differences in the source markdown but should always be semantically equivalent. In the example above the ATX heading # Hello World has been transformed into the equivalent Setext heading.

--model and --contract options

When handling TemplateMark, provide a Concerto model with --model and add --contract if the template is a contract (otherwise it is treated as a clause).

For instance, the following converts a TemplateMark file to its DOM:

markus transform \
  --from markdown_template --to templatemark \
  --model model/model.cto \
  --input text/grammar.tem.md

returns:

{
  "$class": "[email protected]",
  "xmlns": "http://commonmark.org/xml/1.0",
  "nodes": [
    {
      "$class": "[email protected]",
      "name": "top",
      "elementType": "org.accordproject.helloworld.HelloWorldClause",
      "nodes": [
        {
          "$class": "[email protected]",
          "nodes": [
            {
              "$class": "[email protected]",
              "text": "Name of the person to greet: "
            },
            {
              "$class": "[email protected]",
              "name": "name",
              "elementType": "String"
            },
            {
              "$class": "[email protected]",
              "text": "."
            },
            {
              "$class": "[email protected]"
            },
            {
              "$class": "[email protected]",
              "text": "Thank you!"
            }
          ]
        }
      ]
    }
  ]
}

--extension option

Pass --extension path/to/ext.js (repeatable) to register a custom transform extension at runtime. An extension is a module that exports { format?, transforms? } where format declares a new format and transforms declares edges to/from it in the transformation graph. See the integration tests in this package for examples.

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-cli 共发布 1,015 个版本,首次发布于 2019/09/12;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.0latest2026/10/1129 天前
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-cli 的常见问题

@accordproject/markdown-cli 是什么?

A framework for transforming markdown

如何安装 @accordproject/markdown-cli?

在项目目录运行 npm install @accordproject/markdown-cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 markus,可以用 npx markus 直接运行。

@accordproject/markdown-cli 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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

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

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