This module provides an interface for converting Asciidoctor content to various formats using WebAssembly.
It supports conversion to html5
, docbook5
, and manpage
backends, and allows for customization through various options.
The conversion is powered by Ruby's Asciidoctor library running in a WebAssembly (WASM) environment.
You can try out the Asciidoctor WASM in the Playground.
Ensure you have Node.js installed, then install the necessary dependencies:
https://jsr.io/@gem/asciidoctor-wasm
You can import the necessary functions and constants from the module:
import { Asciidoctor, wasmURL } from "@gem/asciidoctor-wasm/browser";
import { Asciidoctor, wasmURL } from "@gem/asciidoctor-wasm/deno";
import { Asciidoctor, wasmURL } from "@gem/asciidoctor-wasm/node";
To initialize the Asciidoctor converter from a WebAssembly module:
const wasmURL = import.meta.resolve('@gem/asciidoctor-wasm/asciidoctor.wasm.gz');
const response = await fetch(url);
const decpressionStream = new DecompressionStream('gzip');
const decompressedResponse = new Response(response.body!.pipeThrough(decpressionStream));
decompressedResponse.headers.set('content-type', 'application/wasm');
const module = await WebAssembly.compileStreaming(decompressedResponse);
const asciidoctor = await Asciidoctor.initFromModule(module);
To initialize the Asciidoctor converter from a WebAssembly binary located at a URL:
const wasmURL = import.meta.resolve('@gem/asciidoctor-wasm/asciidoctor.wasm.gz');
const asciidoctor = await Asciidoctor.initFromURL(wasmURL);
To initialize the Asciidoctor converter from a WebAssembly binary located at a path:
import {fileURLToPath} from 'node:url';
const wasmURL = import.meta.resolve('@gem/asciidoctor-wasm/asciidoctor.wasm.gz');
const wasmPath = fileURLToPath(wasmURL);
const asciidoctor = await Asciidoctor.initFromPath(wasmPath);
Once the converter is initialized, you can use it to convert Asciidoctor content:
const asciidoctorContent = "= Asciidoctor\nDoc Writer\n\nHello, Asciidoctor!";
const options: AsciidoctorOptions = {
backend: "html5",
doctype: "article",
standalone: true,
};
const convertedContent = await asciidoctor.convert(asciidoctorContent, options);
console.log(convertedContent);
deno task ruby:install
: Install dependencies for building Ruby.deno task ruby:build
: Build Ruby.deno task test
: Run the tests.deno task benchmark
: Run the benchmark.This module follows the versioning of the Asciidoctor library it is based on.
0.<asciidoctor>.<asciidoctor-wasm>
<asciidoctor>
: Asciidoctor version; e.g., 2023
is based on Asciidoctor 2.0.23.<asciidoctor-wasm>
: Asciidoctor WebAssembly module version.WASM binary contains a copy of several OSSs as follows:
If you notice the missing license information, please let us know.
This project is licensed under the MIT License. See the LICENSE
file for details.