= Asciidoctor :awestruct-layout: base :homepage: http://asciidoctor.org :asciidoc: http://asciidoc.org :sources: https://github.com/asciidoctor/asciidoctor :issues: https://github.com/asciidoctor/asciidoctor/issues :forum: http://discuss.asciidoctor.org :org: https://github.com/asciidoctor :contributors: https://github.com/asciidoctor/asciidoctor/graphs/contributors :templates: https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/backends :gitscm-next: https://github.com/github/gitscm-next :seed-contribution: https://github.com/github/gitscm-next/commits/master/lib/asciidoc.rb :tilt: https://github.com/rtomayko/tilt :freesoftware: http://www.gnu.org/philosophy/free-sw.html :gist: https://gist.github.com :fork: https://help.github.com/articles/fork-a-repo :branch: http://learn.github.com/p/branching.html :pr: https://help.github.com/articles/using-pull-requests :license: https://github.com/asciidoctor/asciidoctor/blob/master/LICENSE :idprefix: :idseparator: - {homepage}[Asciidoctor] is a pure Ruby processor for converting {asciidoc}[AsciiDoc] source files and strings into HTML 5, DocBook 4.5 and other formats. It's http://rubygems.org/gems/asciidoctor[published as a RubyGem] and is available under the MIT open source license. ifndef::awestruct[] image::https://travis-ci.org/asciidoctor/asciidoctor.png?branch=master[Build Status, link="https://travis-ci.org/asciidoctor/asciidoctor"] endif::awestruct[] Asciidoctor uses a set of built-in ERB templates to render the document to HTML 5 or DocBook 4.5. We've matched the rendered output as close as possible to the default output of the native Python processor. You can override this behavior by providing {tilt}[Tilt]-compatible templates. See the <> section for more details. Asciidoctor currently works (read as 'tested') with Ruby 1.8.7, Ruby 1.9.3, Ruby 2.0.0, JRuby 1.7.4 and Rubinius nightly (on Linux, Mac and Windows). We expect it will work with other versions of Ruby as well and would welcome help in testing it out. The initial code from which Asciidoctor emerged was written by http://github.com/nickh[Nick Hengeveld] to process the git man pages for the {gitscm-next}[Git project site]. Refer to commit history of {seed-contribution}[asciidoc.rb] to view the initial contributions and contributors. The source code can now be found in the {sources}[Asciidoctor source repository] on GitHub. == Installation NOTE: We're working hard to make Asciidoctor a drop-in replacement for AsciiDoc. We're very close, with over 700 tests that ensure compatibility. The march is on towards full compliance and beyond. To install the gem: gem install asciidoctor Or if you prefer bundler, add the asciidoctor gem to your Gemfile, source 'https://rubygems.org' gem 'asciidoctor' then install it using bundler: bundle install If you're running Fedora, you can install the gem using yum: sudo yum install rubygem-asciidoctor The benefit of installing the gem via yum is that yum will also install Ruby if it's not already on your machine. == Usage Asciidoctor has both a command line interface (CLI) and an API. The CLI is a drop-in replacement for the +asciidoc.py+ command from the Python implementation. The API is intended for integration with other software projects and is suitable for server-side applications, such as Rails, Sinatra and GitHub. === Command line interface (CLI) After installing the +asciidoctor+ gem, the +asciidoctor+ commandline interface should be available on your PATH. To invoke it, simply execute: asciidoctor This will use the built-in defaults for options and create a new file in the same directory as the input file, with the same base name, but with the .html extension. There are many other options available and full help is provided via: asciidoctor --help or in the http://asciidoctor.org/man/asciidoctor[man page]. There is also an +asciidoctor-safe+ command, which turns on safe mode by default, preventing access to files outside the parent directory of the source file. This mode is very similar to the safe mode of +asciidoc.py+. === Ruby API To use Asciidoctor in your application, you first need to require the gem: require 'asciidoctor' With that in place, you can start processing AsciiDoc documents. .Loading a document To parse a file into an +Asciidoctor::Document+ object: doc = Asciidoctor.load_file('your_file.asciidoc') You can get information about the document: puts doc.doctitle puts doc.attributes More than likely, you want to just render the document. .Rendering files To render a file containing AsciiDoc markup to HTML 5: Asciidoctor.render_file('your_file.asciidoc', :in_place => true) The command will output to the file +your_file.html+ in the same directory. You can render the file to DocBook 4.5 by setting the +backend+ attribute to 'docbook': Asciidoctor.render_file('your_file.asciidoc', :in_place => true, :attributes => {'backend' => 'docbook'}) The command will output to the file +your_file.xml+ in the same directory. (If you're on Linux, you can view the file using yelp). .Rendering strings To render an AsciiDoc-formatted string: puts Asciidoctor.render('*This* is it.') 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: puts Asciidoctor.render('*This* is it.', :header_footer => true) Now you'll get a full HTML 5 file. As before, you can also produce DocBook 4.5: puts Asciidoctor.render('*This* is it.', :header_footer => true, :attributes => {'backend' => 'docbook'}) If you don't like the output you see, you can change it. Any of it! .Custom templates Asciidoctor allows you to override the {templates}[built-in templates] used to render almost any individual AsciiDoc element. If you provide a directory of {tilt}[Tilt]-compatible templates, named in such a way that Asciidoctor can figure out which template goes with which element, Asciidoctor will use the templates in this directory instead of its built-in templates for any elements for which it finds a matching template. It will fallback to its default templates for everything else. puts Asciidoctor.render('*This* is it.', :header_footer => true, :template_dir => 'templates') The Document and Section templates should begin with +document.+ and +section.+, respectively. The file extension is used by Tilt to determine which view framework it will use to use to render the template. For instance, if you want to write the template in ERB, you'd name these two templates +document.html.erb+ and +section.html.erb+. To use Haml, you'd name them +document.html.haml+ and +section.html.haml+. Templates for block elements, like a Paragraph or Sidebar, would begin with +block_