Asciidoctor HTMLBook is an Asciidoctor backend for converting AsciiDoc documents to HTMLBook documents.

Installation

Add this line to your application’s Gemfile:

gem 'asciidoctor-htmlbook'

And then execute:

$ bundle

Or install it yourself as:

$ gem install asciidoctor-htmlbook

Usage

CLI

$ asciidoctor-htmlbook basic-example.adoc

or

$ asciidoctor -r asciidoctor-htmlbook basic-example.adoc

For more options:

$ asciidoctor-htmlbook -h

API

To use Asciidoctor in your application, you first need to require the gem:

require 'asciidoctor/htmlbook'

Load and Convert a File Using the API

Load from file:

doc = Asciidoctor.load_file 'mysample.adoc', backend: 'htmlbook'
puts doc.convert

Convert file:

Asciidoctor.convert_file 'mysample.adoc', backend: 'htmlbook'

Load and Convert Strings Using the API

Load from string:

doc = Asciidoctor.load '*This* is Asciidoctor.', backend: 'htmlbook'
puts doc.convert

Render string:

Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook'

When rendering a string, the header and footer are excluded by default to make Asciidoctor consistent with other lightweight markup engines like Markdown. If you want the header and footer, just enable it using the :header_footer option:

Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook', header_footer: true

Provide Custom Templates

You can overwrite default templates by adding :template_dir option:

$ asciidoctor-htmlbook -T path/to/templates basic-example.adoc
Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook', template_dir: 'path/to/templates'
Note

asciidoctor-htmlbook template do not compatible with asciidoctor built-in template backend.

View ./templates for more info.

Add Table of Contents

Asciidoctor-htmlbook ignore :toc: attribute in Asciidoctor, instead you can use toc section:

[preface]
== Preface

[toc]
== Table of Contents

== Chapter

So that you can control position of toc.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/rake to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/chloerei/asciidoctor-htmlbook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.