@asciidoctor/core

中文文档
4.2.1发布于 2026/11/02MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 62.9万

Asciidoctor.js: AsciiDoc in JavaScript powered by Asciidoctor

原始使用文档
文档目录6 节
  1. Requirements
  2. Install
  3. Usage
  4. Convert a file
  5. Load without converting
  6. Changelog

Asciidoctor core

This package provides a native JavaScript implementation of Asciidoctor. The code was generated from the Ruby source using Claude Code (claude-sonnet-4-6) and reviewed by a human. It is a pure ESM library that exposes the same functionality:

  • parser
  • built-in converters
  • extensions

The API is asynchronous: all parsing and conversion operations return a Promise.

Requirements

Node.js >= 24

Install

$ npm i @asciidoctor/core --save

Usage

Here is a simple example that converts AsciiDoc to HTML5:

sample.js

import { convert } from '@asciidoctor/core' // ①

const content = 'https://asciidoctor.org[*Asciidoctor*] running on Node.js!'
const html = await convert(content) // ②
console.log(html) // ③
  1. Import convert from the Asciidoctor native library (ESM, named export)
  2. Convert AsciiDoc content to HTML5 — the call returns a Promise and must be awaited
  3. Print the HTML5 output to the console

Save the file as sample.js and run it using the node command:

$ node sample.js

You should see the following output in your terminal:

<div class="paragraph">
<p><a href="https://asciidoctor.org"><strong>Asciidoctor</strong></a> running on Node.js!</p>
</div>

Convert a file

convert-file.js

import { convertFile } from '@asciidoctor/core'

const html = await convertFile('document.adoc', { safe: 'safe' })
console.log(html)

Load without converting

Use load when you need to inspect the parsed document model before (or instead of) converting:

load.js

import { load } from '@asciidoctor/core'

const doc = await load('== Hello, World!\n\nThis is Asciidoctor core.')
console.log(doc.getTitle())    // Hello, World!
console.log(doc.getBlocks())   // array of top-level blocks
const html = await doc.convert()
console.log(html)

Changelog

Refer to the CHANGELOG for a complete list of changes.

版本与发布记录

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

版本发布日期距今
4.2.1latest2026/11/025 天前
4.2.02026/11/025 天前
4.1.12026/10/051 个月前
4.1.02026/09/221 个月前
4.0.112026/08/182 个月前
4.0.102026/08/182 个月前

其他发布通道:latest-2 → 2.2.9,testing → 4.0.0-alpha.6。

关于 @asciidoctor/core 的常见问题

@asciidoctor/core 是什么?

Asciidoctor.js: AsciiDoc in JavaScript powered by Asciidoctor

如何安装 @asciidoctor/core?

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

@asciidoctor/core 支持 TypeScript 吗?

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

@asciidoctor/core 支持 ESM 还是 CommonJS?

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

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

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

@asciidoctor/core 可以商用吗?

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

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

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

@asciidoctor/core 还在维护吗?

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