Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Asciidoctor.js 2+ #254

Merged
merged 5 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
obilodeau marked this conversation as resolved.
Show resolved Hide resolved

$ 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
ggrossetie marked this conversation as resolved.
Show resolved Hide resolved

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');
ggrossetie marked this conversation as resolved.
Show resolved Hide resolved

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

20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +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"
ggrossetie marked this conversation as resolved.
Show resolved Hide resolved
},
"files": [
"dist",
"LICENSE.adoc",
"README.adoc"
],
"files": [],
ggrossetie marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -29,10 +27,10 @@
"library",
"backend",
"template",
"reveal.js",
"jade"
"reveal.js"
],
"authors": [
"Olivier Bilodeau (https://github.com/obilodeau)",
"Guillaume Grossetie (https://github.com/mogztter)"
],
"license": "MIT",
Expand All @@ -41,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