AsciiDoc(tor) syntax reference and tricks
Adding a table of contents
Enable the toc
attribute on the document to generate a table of contents automatically:
```asciidoc
= Document Title
:toc:
Document contents.
Links
https://asciidoctor.org - automatic!
https://asciidoctor.org[Asciidoctor]
https://github.com/asciidoctor[Asciidoctor @ *GitHub*]
Reference-style Links
AsciiDoc doesn’t have a dedicated syntax for reference links, but this can easily be achieved using attributes:
= Document Title
:example-link: https://example.com/
Please {example-link}[visit the example] now.
Code blocks
Literal blocks:
....
Code here
....
Code block with title and syntax highlighting:
.app.rb
[source,ruby]
----
require 'sinatra'
get '/hi' do
"Hello World!"
end
----
Code block with callouts:
[source,ruby]
----
require 'sinatra' // <1>
get '/hi' do // <2>
"Hello World!" // <3>
end
----
<1> Library import
<2> URL mapping
<3> HTTP response body
Code block sources from file:
[source,ruby]
----
include::app.rb[]
----
For more examples, see https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/#source-code
Syntax highlighting
Syntax highlighting is enabled by setting the source-highlighter attribute in the document header or passed as an argument, for example:
:source-highlighter: pygments
The valid options are coderay
, highlightjs
, prettify
, and pygments
.