Node / JavaScript Setup
Prerequisites
First you must install and configure Node on your machine.
Install
We recommend installing the dependencies in a project directory, such as the directory where your AsciiDoc presentations are stored.
If you don’t have a package.json file in your project directory, you can create one to eliminate warnings during the installation using:
$ npm init -y
You can now install the dependencies:
$ npm i --save asciidoctor @asciidoctor/reveal.js
|
|
Convert AsciiDoc into slides
Once the dependencies are installed, verify that the asciidoctor-revealjs command is available.
On Linux and macOS, open a terminal and type:
$ npx asciidoctor-revealjs --version
On Windows, open PowerShell and type:
$ .\node_modules\.bin\asciidoctor-revealjs.cmd --version
The command should report the Asciidoctor CLI version in the terminal:
Asciidoctor reveal.js 6.0.0 using Asciidoctor.js 4.2.1 (Asciidoctor 2.0.26) [https://asciidoctor.org]
Runtime Environment (node v24.16.0 on linux)
CLI version 4.2.1
If you don’t have an existing presentation, you can create a sample presentation named presentation.adoc:
= Title Slide
== Slide One
* Foo
* Bar
* World
To convert the sample presentation into slides, open a terminal and type:
$ npx asciidoctor-revealjs presentation.adoc
On Windows, open PowerShell and type:
$ .\node_modules\.bin\asciidoctor-revealjs.cmd presentation.adoc
The above command will generate a file named presentation.html. You can open this file in a browser.
Using the JavaScript API
Alternatively, you can use the JavaScript API to register the converter and convert a document.
Asciidoctor.js 4.0 is an ESM, native JavaScript package and its conversion functions are asynchronous, so use import and await:
// Load Asciidoctor.js and register the reveal.js converter
import { convertFile } from 'asciidoctor'
import { register } from '@asciidoctor/reveal.js'
register() (1)
// Convert the document 'presentation.adoc' using the reveal.js converter
await convertFile('presentation.adoc', { safe: 'safe', backend: 'revealjs' }) (2)
| 1 | Registers the revealjs (and reveal.js) backends and the highlight.js adapter |
| 2 | Creates a file named presentation.html (in the directory where the command is run) |
To execute the script, open a terminal and type:
$ node convert-slides.mjs
You can now open the presentation.html file in your browser.