Skip to content

Commit

Permalink
Explain how to use the Asciidoctor CLI to convert an AsciiDoc file in…
Browse files Browse the repository at this point in the history
…to slides
  • Loading branch information
ggrossetie committed Dec 9, 2019
1 parent 11140a9 commit 02c004f
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ endif::[]
ifdef::env-github[]
image:https://travis-ci.org/asciidoctor/asciidoctor-reveal.js.svg?branch=master[Build Status,link=https://travis-ci.org/asciidoctor/asciidoctor-reveal.js]
image:http://img.shields.io/gem/v/asciidoctor-revealjs.svg[gem, link=https://rubygems.org/gems/asciidoctor-revealjs]
image:http://img.shields.io/npm/v/asciidoctor-reveal.js.svg[npm, link=https://www.npmjs.org/package/asciidoctor-reveal.js]
image:https://img.shields.io/npm/v/@asciidoctor/reveal.js.svg[npm, link=https://www.npmjs.org/package/@asciidoctor/reveal.js]
endif::[]

// IMPORTANT: Changes made to this description should be sync'ed with the readme field in package.json.
Expand Down Expand Up @@ -130,38 +130,38 @@ TIP: If you are using https://pages.github.com/[GitHub Pages], plan ahead by kee

=== Prerequisites

First you must install and configure {uri-nodejs-download}[Node.js] on your machine.
First you must install and configure {uri-nodejs-download}[Node] on your machine.

=== Install

Using npm:
We recommend to install 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:

Create a directory to place slides. Initialize the directory to store npm packages within that directory.
$ echo {} > package.json # or `npm init` if you prefer

$ echo {} > package.json # eliminates warnings, use `npm init` if you prefer
$ npm i --save asciidoctor-reveal.js
You can now install the dependencies:

=== Rendering the AsciiDoc into slides
$ npm i --save asciidoctor @asciidoctor/reveal.js

Once the package is installed, you can convert AsciiDoc files using reveal.js converter.
Here we are converting a file named `presentation.adoc` into a reveal.js presentation using Node.js:
=== Convert AsciiDoc into slides

.asciidoctor-revealjs.js
[source, javascript]
----
// Load asciidoctor.js and asciidoctor-reveal.js
var asciidoctor = require('asciidoctor.js')();
var asciidoctorRevealjs = require('asciidoctor-reveal.js');
asciidoctorRevealjs.register()
Once the dependencies are installed, verify that the `asciidoctor` command is available by running:

// Convert the document 'presentation.adoc' using the reveal.js converter
var options = {safe: 'safe', backend: 'revealjs'};
asciidoctor.convertFile('presentation.adoc', options); // <1>
$ $(npm bin)/asciidoctor --version

The command should report the Asciidoctor CLI version in the terminal:

[source,console]
----
<1> Creates a file named `presentation.html` (in the directory where command is run)
Asciidoctor.js 2.0.3 (Asciidoctor 2.0.9) [https://asciidoctor.org]
Runtime Environment (node v10.15.1 on linux)
CLI version 2.0.1
----

If you don't have an existing presentation, you can create a sample presentation named [.path]_presentation.adoc_:

.presentation.adoc
[source, asciidoc]
[source,asciidoc]
----
= Title Slide
Expand All @@ -173,12 +173,36 @@ asciidoctor.convertFile('presentation.adoc', options); // <1>
----

To render the slides, run:
To convert the sample presentation into slides, open a terminal and type:

node asciidoctor-revealjs.js
$ $(npm bin)/asciidoctor -r @asciidoctor/reveal.js -b revealjs presentation.adoc

You can open the `presentation.html` file in your browser and enjoy!
The above command will generate a file named [.path]_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:

.convert-slides.js
[source,javascript]
----
// Load Asciidoctor.js and the reveal.js converter
var asciidoctor = require('@asciidoctor/core')()
var asciidoctorRevealjs = require('@asciidoctor/reveal.js')
asciidoctorRevealjs.register()
// Convert the document 'presentation.adoc' using the reveal.js converter
var options = { safe: 'safe', backend: 'revealjs' }
asciidoctor.convertFile('presentation.adoc', options) // <1>
----
<1> Creates a file named `presentation.html` (in the directory where command is run)

To execute the script, open a terminal and type:

$ node convert-slides.js

You can open the `presentation.html` file in your browser and enjoy!

== Syntax Examples

Expand Down

0 comments on commit 02c004f

Please sign in to comment.