npm.io
4.0.0 • Published 6d ago

@asciidoctor/core

Licence
MIT
Version
4.0.0
Deps
0
Size
2.7 MB
Vulns
0
Weekly
140.0K

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.

Keywords