1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
= 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 <<usage>> 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.2 and Rubinius 1.2.4 (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 <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 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_<style>.+. For instance, to override the default Paragraph
template with an ERB template, put a file named
+block_paragraph.html.erb+ in the template directory you pass to the
+Document+ constructor using the +:template_dir+ option.
For more usage examples, see the (massive) test suite.
== Differences from AsciiDoc
While Asciidoctor aims to be compliant with the AsciiDoc syntax, there
are some differences which are important to keep in mind. In some cases,
it's to enforce a rule we believe is too lax or ambiguous in AsciiDoc.
In other cases, it's a tradeoff for speed, smarter processing or a
feature we just haven't yet implemented. (You'll also notice that
Asciidoctor executes about 25x as fast as AsciiDoc).
Here are the known cases where Asciidoctor differs from AsciiDoc:
* Asciidoctor enables safe mode by default when using the API
(+SafeMode::SECURE+)
* Asciidoctor safe mode is even more safe than AsciiDoc's safe mode
* Asciidoctor enforces symmetric block delimiters (the length of start
and end delimiters for a block must match!)
* Section title underlines must be within 1 character of the length of
the title (AsciiDoc allows an offset of 3)
* Asciidoctor's default HTML backend matches AsciiDoc's HTML 5 backend
(whereas XHTML 1.1 is the default HTML backend in AsciiDoc)
* Asciidoctor adds viewport meta tag to +<head>+ to optimize mobile viewing
* Asciidoctor handles inline anchors more cleanly
** AsciiDoc adds an +<a>+ tag in the line and that markup gets caught in
the generated id
** Asciidoctor promotes the id of the anchor as the section id
* Asciidoctor strips XML entities from the section title before
generating the id (makes for cleaner section ids)
* Asciidoctor uses +<code>+ instead of +<span class="monospace">+ around
inline literal text in the HTML backend
* Asciidoctor does not wrap email next to author name in header in
angle brackets
* Asciidoctor allows email field to be a URL and renders it as such
* Asciidoctor is much more lenient about attribute list parsing (double
quotes are rarely needed, though you may want to keep them for
compatibility)
* Asciidoctor recognizes +opts+ as an alias for the +options+ attribute.
* Asciidoctor creates xref labels using the text from the linked section
title when rendering HTML to match how DocBook works
* Asciidoctor allows commas to be used in xref labels, whereas AsciiDoc
cuts off the label at the location of the first comma
* Asciidoctor removes indentation for non-literal paragraphs in a list
item
+
NOTE: In general, Asciidoctor handles whitespace much more intelligently
+
* In Asciidoctor, a horizontal ruler can have attributes
* Asciidoctor wraps +<col>+ elements in +<colgroup>+ in tables
* Asciidoctor uses +<code>+ around content in monospaced table cells
* Asciidoctor skips over line comments in tables, whereas AsciiDoc doesn't
* Asciidoctor uses its own API rather than a command line invocation to
handle table cells that have AsciiDoc content
* Asciidoctor supports resolving variables from parent document in table
cells with AsciiDoc content
* AsciiDoc doesn't carry over the doctype attribute passed from the
commandline when rendering AsciiDoc table cells, whereas Asciidoctor does
* Asciidoctor does not require commas between attributes with quoted
values in a block attribute list
* Asciidoctor strips the file extension from the target image when
generating alt text if no alt text is provided
* Asciidoctor reifies the toc in the header of the document instead of
relying on JavaScript to create it
* Asciidoctor sets CSS class on toc element, read from the +toc-class+
attribute; defaults to toc attribute name (+toc+ or +toc2+).
* Asciidoctor honors the id, title, role and levels attributes set on
the toc macro.
* Asciidoctor does not output two TOCs with the same id.
* Asciidoctor is nice about using a section title syntax inside a
delimited block by simply ignoring it (AsciiDoc issues warnings)
* Asciidoctor honors the alternate style name "discrete" for a floating
title (i.e., +[discrete]+)
* Asciidoctor supports syntax highlighting of listing or literal blocks
that have the "source" style out of the box
** Asciidoctor honors the source-highlighter values +coderay+ and
+highlightjs+, using CodeRay or highlight.js, respectively
** Asciidoctor does not currently support Pygments for source
highlighting
* Asciidoctor sets these additional intrinsic attributes
+asciidoctor+::
indicates Asciidoctor is being used; useful for conditional
processing
+asciidoctor-version+::
indicates which version of Asciidoctor is in use
* Asciidoctor does not support deprecated tables (you don't want them
anyway)
* Use can set the extension for icons using the +icontype+ attribute
(AsciiDoc defaults to .png)
* AsciiDoc uses the +<blockquote>+ for the content and +<cite>+ tag for
attribution title in the HTML output for quote blocks, requiring some
additional styling to match AsciiDoc
+
blockquote.content { padding: 0; margin; 0 }
cite { color: navy; }
+
* Asciidoctor does not support the deprecated index term syntax (`++`
and `+++`)
* Asciidoctor includes a modern default stylesheet based on Foundation.
* Asciidoctor links to, rather than embeds, the default stylesheet into
the document by default (e.g., +linkcss+). To include the default
stylesheet, you can either use the +copycss+ attribute to tell
Asciidoctor to copy it to the output directory, or you can embed it
into the document using the +linkcss!+ attribute. You can also provide
your own stylesheet using the +stylesheet+ attribute.
* Asciidoctor introduces the +hardbreaks+ attribute, which inserts a
line break character after each line of wrapped text
* Asciidoctor introduces the +idseparator+ attribute to customize the
separator used in generated section ids (AsciiDoc hardcodes +_+)
* Asciidoctor does not support system evaluation macros
* Asciidoctor does not support displaying comments
* Asciidoctor properly calculates author initials if attribute reference
is used in name
* Asciidoctor allows the author and revision attributes to be referenced
in subsequent attribute entries in header (unlike AsciiDoc)
* Asciidoctor allows multiple authors to be defined, separated by
semicolon. In DocBook backend, the authors are listed in an
+<authorgroup>+ element.
* Asciidoctor allows the document id to be set using [[id]] above the
document header (adds id attribute to +<body>+ tag)
* Assigning value to the +listing-caption+ attribute will enable
automatic captions for listings (like examples, tables and figures)
* The +ifeval::[]+ macro is constrained for the strict purpose of
comparing values of attributes
* The +include::[]+ macro is converted to a link to the target document
when SafeMode is SECURE or greater (this makes for a friendly
experience on GitHub)
* Asciidoctor supports up to 6 section levels (to cover all heading levels in
HTML) whereas AsciiDoc stops at 5; note the 6 section level is only available
using the single-line section title syntax
* Admonition block style is added to class of outer div in html5 backend
in Asciidoctor
* Admonition block caption can be overridden in Asciidoctor using the
+caption+ block attribute
* Asciidoctor will parse attributes in link macros if the
+use-link-attrs+ attribute is set on the document.
If there's a difference you don't see in this list, check the {issues}[issue
tracker] to see if it's an outstanding feature, or file an issue to report the
difference.
== Contributing
In the spirit of {freesoftware}[free software], 'everyone' is encouraged to
help improve this project.
Here are some ways *you* can contribute:
* by using alpha, beta, and prerelease versions
* by reporting bugs
* by suggesting new features
* by writing or editing documentation
* by writing specifications
* by writing code -- 'No patch is too small.'
** fix typos
** add comments
** clean up inconsistent whitespace
** write tests!
* by refactoring code
* by fixing {issues}[issues]
* by reviewing patches
== Submitting an Issue
We use the {issues}[GitHub issue tracker] associated with this project
to track bugs and features. Before submitting a bug report or feature
request, check to make sure it hasn't already been submitted. When
submitting a bug report, please include a {gist}[Gist] that includes any
details that may help reproduce the bug, including your gem version,
Ruby version, and operating system.
Most importantly, since Asciidoctor is a text processor, reproducing
most bugs requires that we have some snippet of text on which
Asciidoctor exhibits the bad behavior.
An ideal bug report would include a pull request with failing specs.
== Submitting a Pull Request
. {fork}[Fork the repository].
. {branch}[Create a topic branch].
. Add tests for your unimplemented feature or bug fix.
. Run +bundle exec rake+.
If your tests pass, return to step 3.
. Implement your feature or bug fix.
. Run +bundle exec rake+.
If your tests fail, return to step 5.
. Add documentation for your feature or bug fix.
. If your changes are not 100% documented, go back to step 7.
. Add, commit, and push your changes.
. {pr}[Submit a pull request].
== Supported Ruby Versions
This library aims to support the following Ruby implementations:
* Ruby 1.8.7
* Ruby 1.9.3
* Ruby 2.0.0
* JRuby 1.7.2
* Rubinius 1.2.4
If something doesn't work on one of these interpreters, it should be
considered a bug.
If you would like this library to support another Ruby version, you may
volunteer to be a maintainer. Being a maintainer entails making sure all
tests run and pass on that implementation. When something breaks on your
implementation, you will be personally responsible for providing patches
in a timely fashion. If critical issues for a particular implementation
exist at the time of a major release, support for that Ruby version may
be dropped.
== Resources
Project home page:: {homepage}
Source repository:: {sources}
Issue tracker:: {issues}
Mailinglist / forum:: {forum}
GitHub organization:: {org}
== Authors
*Asciidoctor* was written by https://github.com/mojavelinux[Dan Allen],
https://github.com/erebor[Ryan Waldron],
https://github.com/lightguard[Jason Porter], https://github.com/nickh[Nick
Hengeveld] and {contributors}[other contributors].
*AsciiDoc* was written by Stuart Rackham and has received contributions
from many other individuals.
== Copyright
Copyright (C) 2012-2013 Dan Allen and Ryan Waldron. Free use of this
software is granted under the terms of the MIT License.
See the {license}[LICENSE] file for details.
// vim: tw=72
|