= Asciidoctor Dan Allen ; Ryan Waldron ; Sarah White :page-layout: base :homepage: http://asciidoctor.org :asciidoc: http://asciidoc.org :gem: http://rubygems.org/gems/asciidoctor :toolchain: http://asciidoctor.org/docs/install-toolchain :install-mac: http://asciidoctor.org/docs/install-asciidoctor-macosx :render: http://asciidoctor.org/docs/render-documents :factory: http://asciidoctor.org/docs/produce-custom-themes-using-asciidoctor-stylesheet-factory :java: http://asciidoctor.org/docs/install-and-use-asciidoctor-java-integration :man: http://asciidoctor.org/man/asciidoctor :sources: https://github.com/asciidoctor/asciidoctor :tests: https://github.com/asciidoctor/asciidoctor/tree/master/test :issues: https://github.com/asciidoctor/asciidoctor/issues :forum: http://discuss.asciidoctor.org :irc: irc://irc.freenode.org/#asciidoctor :news: http://asciidoctor.org/news :docs: http://asciidoctor.org/docs :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 :changelog: https://github.com/asciidoctor/asciidoctor/blob/master/CHANGELOG.adoc :license: https://github.com/asciidoctor/asciidoctor/blob/master/LICENSE :idprefix: :idseparator: - :language: ruby {homepage}[Asciidoctor] is an open source text processor and publishing toolchain for transforming {asciidoc}[AsciiDoc] markup into HTML 5, DocBook 4.5 and 5.0 and other custom formats. Asciidoctor is written entirely in Ruby, packaged as a RubyGem and published to {gem}[RubyGems.org]. There are also Fedora, Debian and Ubuntu packages available for installing Asciidoctor. Asciidoctor is released under the MIT license. ifdef::env-github[] *Project health:* image:https://travis-ci.org/asciidoctor/asciidoctor.png?branch=master[Build Status, link="https://travis-ci.org/asciidoctor/asciidoctor"] endif::env-github[] == AsciiDoc Processing Asciidoctor reads and parses AsciiDoc markup (from a file or string) and feeds the parsed result to a set of built-in templates to render the document as HTML 5, DocBook 4.5 or DocBook 5.0. Asciidoctor is a drop-in replacement for the original AsciiDoc processor. We've matched the output to that produced by the AsciiDoc Python processor as faithfully as possible. You can override the built-in templates, or produce a custom format, by pointing the processor at a set of template files written in a language supported by {tilt}[Tilt]. See the <> section for more details. NOTE: With few exceptions, Asciidoctor is compliant with the original AsciiDoc processor. Asciidoctor has well over 1,000 tests to ensure compatibility with the AsciiDoc syntax. We continue to work hard to ensure Asciidoctor continues to serve as a drop-in replacement for AsciiDoc. == Operating Systems Asciidoctor works on Linux, OSX (Mac) and Windows. == Dependency and Configuration Requirements Asciidoctor requires one of the following implementations of Ruby: * Ruby 1.8.7 * Ruby 1.9.3 * Ruby 2.0 * Ruby 2.1 * JRuby 1.7 (Ruby 1.8 and 1.9 modes) * Rubinius 2.1.1 * Opal (JavaScript) We expect Asciidoctor to work with other versions of Ruby as well. We welcome your help testing those versions if you are interested in seeing them supported. // QUESTION What is considered configuration information? // QUESTION What about other sub-projects of Asciidoctor that require Tilt? // TODO fill in this section and enable //== List of files/directory structure // //Optional depending on the complexity of the project The latest source code is located in the {sources}[Asciidoctor git repository] on GitHub. == Installation Asciidoctor can be installed via the +gem+ command, bundler, or popular Linux package managers. === gem install To install Asciidoctor using the +gem+ command: . Open a terminal . Type the +gem+ command $ gem install asciidoctor === bundle install (Bundler) To install Asciidoctor using bundler: . Open your system Gemfile . Add the +asciidoctor+ gem to your Gemfile using the following text [source] source 'https://rubygems.org' gem 'asciidoctor' . Save the Gemfile . Open a terminal . Install the gem with bundler $ bundle install === yum install (Fedora) To install Asciidoctor on Fedora 17 or greater: . Open a terminal . Type the +yum+ command $ sudo yum install rubygem-asciidoctor The benefit of installing the gem via +yum+ is that the package manager will also install Ruby and RubyGems if not already on your machine. === apt-get install (Debian, Ubuntu) To install Asciidoctor on Debian Sid or Ubuntu Saucy or greater: . Open a terminal . Type the +apt-get+ command $ sudo apt-get install asciidoctor The benefit of installing the gem via +apt-get+ is that the package manager will also install Ruby and RubyGems if not already on your machine. === Other installation options * {toolchain}[Installing the Asciidoctor toolchain] * {install-mac}[Installing Asciidoctor on Mac OS X] == Upgrading If you have an earlier version of Asciidoctor installed, you can update it using the +gem+ command: $ gem update asciidoctor [TIP] -- If you accidentally use +gem install+ instead of +gem update+ then you will have both versions installed. If you wish to remove the older version use the +gem+ command: $ gem cleanup asciidoctor -- On Fedora, you can update it using: $ sudo yum update rubygem-asciidoctor TIP: Your Fedora system may be configured to automatically update packages, in which case no further action is required by you. Refer to the http://docs.fedoraproject.org[Fedora docs] if you are unsure. On Debian or Ubuntu, you can update it using: $ sudo apt-get upgrade asciidoctor NOTE: The Fedora, Debian and Ubuntu packages will not be available right away after a release of the RubyGem. It may take several weeks before the packages become available for a new release. If you need the latest version immediately, use the +gem install+ option. == Usage If the Asciidoctor gem installed successfully, the +asciidoctor+ command line interface (CLI) will be available on your PATH. To invoke it, execute: $ asciidoctor --version In the console, you should see: Asciidoctor 0.1.4 [http://asciidoctor.org] In addition to the CLI, Asciidoctor provides a Ruby API The API is intended for integration with other software projects and is suitable for server-side applications, such as Rails, Sinatra and GitHub. TIP: Asciidoctor also has a Java API that mirrors the Ruby API. The Java API calls through to the Ruby API using an embedded JRuby runtime. See the {java}[Asciidoctor Java integration project] for more information. === Command line interface (CLI) Asciidoctor's CLI is a drop-in replacement for the +asciidoc.py+ command from the Python implementation. To invoke Asciidoctor from the CLI, execute: $ asciidoctor [asciidoc-file] 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 {man}[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+. Additional documentation: * {render}[How do I render a document?] * {factory}[How do I use the Asciidoctor stylesheet factory to produce custom themes?] === Ruby API To use Asciidoctor in your application, you first need to require the gem: [source] require 'asciidoctor' With that in place, you can start processing AsciiDoc documents. ==== Loading a document To parse a file into an +Asciidoctor::Document+ object: [source] doc = Asciidoctor.load_file 'sample.adoc' You can get information about the document: [source] require 'pp' puts doc.doctitle puts doc.attributes More than likely, you will want to render the document. ==== Rendering files To render a file containing AsciiDoc markup to HTML 5, use: [source] Asciidoctor.render_file 'sample.adoc', :in_place => true The command will output to the file +sample.html+ in the same directory. You can render the file to DocBook 4.5 by setting the +:backend+ option to +:docbook+: [source] Asciidoctor.render_file 'sample.adoc', :in_place => true, :backend => :docbook The command will output to the file +sample.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: [source] puts Asciidoctor.render '*This* is http://asciidoc.org[AsciiDoc]!' 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: [source] puts Asciidoctor.render '*This* is http://asciidoc.org[AsciiDoc]!', :header_footer => true Now you'll get a full HTML 5 file. If you only want the inline markup to be processed, set the +:doctype+ option to +'inline'+: [source] puts Asciidoctor.render '*This* is http://asciidoc.org[AsciiDoc]!', :doctype => :inline As before, you can also produce DocBook 4.5: [source] puts Asciidoctor.render '*This* is http://asciidoc.org[AsciiDoc]!.', :header_footer => true, :backend => :docbook If you don't like the output you see, you can change it. Any of it! ==== Using 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. [source] puts Asciidoctor.render '*This* is http://asciidoc.org[AsciiDoc]!', :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 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_