Skip to content

Commit

Permalink
Merge pull request #254 from Mogztter/issue-252-asciidoctor200
Browse files Browse the repository at this point in the history
Upgrade to Asciidoctor.js 2+
  • Loading branch information
obilodeau committed Dec 10, 2019
2 parents 4daa4f9 + 9293b8d commit d1a01eb
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 59 deletions.
79 changes: 56 additions & 23 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,38 +130,43 @@ 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.
$ npm init -y

$ 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.
On Linux and macOS, open a terminal and type:

// 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

On Windows, open PowerShell and type:

$ .\node_modules\.bin\asciidoctor.cmd --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 +178,40 @@ 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!
On windows, open PowerShell and type:

$ .\node_modules\.bin\asciidoctor.cmd -r asciidoctor-reveal.js -b revealjs presentation.adoc

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
2 changes: 1 addition & 1 deletion npm/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const examplesDir = 'examples';
log.task('examples');

// Load asciidoctor.js and local asciidoctor-reveal.js
const asciidoctor = require('asciidoctor.js')();
const asciidoctor = require('@asciidoctor/core')();
const asciidoctorRevealjs = require('../build/asciidoctor-reveal.js');

// Register the reveal.js converter
Expand Down
79 changes: 50 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
"description": "A reveal.js converter for Asciidoctor.js. Write your slides in AsciiDoc!",
"main": "dist/main.js",
"engines": {
"node": ">=4",
"npm": ">=3.0.0"
"node": ">=8.11",
"npm": ">=5.0.0"
},
"files": [],
"scripts": {
"build": "node npm/build.js",
"test": "node test/smoke.js",
"examples": "node npm/examples.js"
},
"repository": {
"type": "git",
"url": "https://github.com/asciidoctor/asciidoctor-reveal.js.git"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"asciidoc",
"asciidoctor",
Expand All @@ -37,10 +39,10 @@
},
"homepage": "https://github.com/asciidoctor/asciidoctor-reveal.js",
"dependencies": {
"asciidoctor.js": "1.5.9",
"reveal.js": "3.7.0"
},
"devDependencies": {
"@asciidoctor/core": "^2.0.0",
"bestikk-log": "0.1.0",
"expect.js": "0.3.1"
}
Expand Down
4 changes: 2 additions & 2 deletions test/smoke.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const asciidoctor = require('asciidoctor.js')()
const asciidoctor = require('@asciidoctor/core')()
const asciidoctorRevealjs = require('../dist/main.js')
//require('../dist/main.js')

Expand All @@ -7,7 +7,7 @@ const expect = require('expect.js')
// Register the reveal.js converter
asciidoctorRevealjs.register()

const options = {safe: 'safe', backend: 'revealjs', 'header_footer': true}
const options = {safe: 'safe', backend: 'revealjs', standalone: true}
const content = `= Title Slide
== Slide One
Expand Down

0 comments on commit d1a01eb

Please sign in to comment.