@asciidoctor/reducer

中文文档
1.1.2发布于 2025/05/10MITCommonJS零依赖近 30 天下载 2.6万

An Asciidoctor.js extension to reduce an AsciiDoc document containing includes and conditionals to a single AsciiDoc document.

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. Extension
  4. Copyright and License
  5. Trademarks

Asciidoctor Reducer

An Asciidoctor.js extension that reduces an AsciiDoc document containing include directives to a single AsciiDoc document by expanding the includes reachable from the parent document. Additionally, the extension evaluates preprocessor conditionals (unless the option to preserve them is enabled), only keeping those lines from conditions which are true. If the document does not contain any preprocessor directives, the extension provides access to the unmodified source.

(The CLI and API are not currently available in the JavaScript version).

Install

This package depends on the asciidoctor package (>= 2.2.0, < 3.0.0), but doesn’t declare it as a dependency. Therefore, you must install that package when installing this one.

$ npm i asciidoctor @asciidoctor/reducer

If you’re using the extension with Antora, there’s no need to install the asciidoctor package as Antora provides it.

Usage

Extension

You can use this extension in combination with the load API provided by Asciidoctor. If you want to register the extension globally, require the library as follows:

const Asciidoctor = require('asciidoctor')()

require('@asciidoctor/reducer').register()

When you use the Asciidoctor load API, the document will automatically be reduced. You can access the reduced source by calling either the getSource() or getSourceLines() on the loaded document.

const doc = Asciidoctor.loadFile('main.adoc', { safe: 'safe' })

console.log(doc.getSource())

You can pass a registry instance to the register method to register the extension with a scoped registry (scoped to the load API call).

const Asciidoctor = require('asciidoctor')()

const registry = Asciidoctor.Extensions.create()
require('@asciidoctor/reducer').register(registry)

const doc = Asciidoctor.loadFile('main.adoc', { extension_registry: registry, safe: 'safe' })

You can also require @asciidoctor/reducer/extensions to access the Extensions class.

Copyright (C) 2021-present Dan Allen and the individual contributors to this project. Use of this software is granted under the terms of the MIT License.

Trademarks

AsciiDoc(R) and AsciiDoc Language(TM) are trademarks of the Eclipse Foundation, Inc.

版本与发布记录

@asciidoctor/reducer 共发布 3 个版本,首次发布于 2024/11/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.2latest2025/05/101.5 年前
1.1.12025/03/271.6 年前
1.1.02024/11/251.9 年前

关于 @asciidoctor/reducer 的常见问题

@asciidoctor/reducer 是什么?

An Asciidoctor.js extension to reduce an AsciiDoc document containing includes and conditionals to a single AsciiDoc document.

如何安装 @asciidoctor/reducer?

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

@asciidoctor/reducer 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/asciidoctor__reducer 是否存在。

@asciidoctor/reducer 支持 ESM 还是 CommonJS?

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

@asciidoctor/reducer 需要什么版本的 Node.js?

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

@asciidoctor/reducer 可以商用吗?

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

@asciidoctor/reducer 的下载量有多少?

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

@asciidoctor/reducer 还在维护吗?

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