烟道核心
这个软件包提供了本地JavaScript执行 Asciidodor. 该代码来自 Ruby 源代码使用 克劳德代码 (claude-sonnet-4-6),并被人类审查. 它是一个纯粹的无害环境管理库,揭示了同样的功能:
- 解析器
- 内置转换器
- 扩展
API 是一个同步: 所有解析和转换操作返回 a Promise。 。 。 .
所需资源
节点.js 24
安装
$ npm i @asciidoctor/core --save
使用量
以下是将 AsciiDoc 转换为 HTML5 的简单示例 :
样本.js
import { convert } from '@asciidoctor/core' // ①
const content = 'https://asciidoctor.org[*Asciidoctor*] running on Node.js!'
const html = await convert(content) // ②
console.log(html) // ③
- 导入
convert从 Ascidoctor 本地图书馆(ESM, 命名导出) - 将 AsciiDoc 内容转换为 HTML5——调用返回 a
Promise并且必须等待 - 打印 HTML5 输出到控制台
文件另存为 样本.js 并运行它使用 node 命令 :
$ node sample.js
您应该在终端中看到以下输出 :
<div class="paragraph">
<p><a href="https://asciidoctor.org"><strong>Asciidoctor</strong></a> running on Node.js!</p>
</div>
转换文件
转换文件.js
import { convertFile } from '@asciidoctor/core'
const html = await convertFile('document.adoc', { safe: 'safe' })
console.log(html)
不转换而装入
使用 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)
更改日志
参见 变化 用于完整更改列表.