はじめに
AsciiDoc のチートシートです。
Markdown すらまともに書けない自分が、Markdown を使って AsciiDoc を書いているので、頭が混乱してくる。
(加えてめちゃくちゃ時間がかかる。。。)
よく使う記法
こちらのページを参考に、自分がよく使うものをピックアップしています。
基本的に、ソフトウェアの仕様書や、情報共有のためのメモを最低限、書くことができる。くらいのものを選んでいます。
ヘッダ
以下は Level 3
までしか書いていないが、 Level 5
(=の数は6つ) まで可能。
= Document Title (Level 0)
== Level 1 Section
=== Level 2 Section
==== Level 3 Section
改行
改行するためには、 +
(半角スペースと+)が必要。
もしくは、[%hardbreaks]
を入れると、そのブロック内は強制的に改行される。
Roses are red, +
violets are blue.
[%hardbreaks]
A ruby is red.
Java is black.
テーブル
タイトル、ヘッダー付きの3行2列のテーブル。
.Table Title
|===
|Column 1, Header Row |Column 2, Header Row
|Cell in column 1, row 1
|Cell in column 2, row 1
|Cell in column 1, row 2
|Cell in column 2, row 2
|===
イメージ(画像)
image::URL[代替テキスト]
のフォーマットで画像が挿入できる。
代替テキスト
とは、何らかの原因で画像が表示されなかったときに表示されるテキストのことらしい。(ググれば出てくる)
代替テキストは省略して、[]
のみでも問題ない。
また、テーブルのように、.Image Ttile
で、イメージにタイトルを付けることもできる。
.Image Title
image::https://asciidoctor.org/images/octocat.jpg[GitHub mascot]
リスト
番号なしリスト
いわゆる、番号のない箇条書き。*
(アスタリスクと半角スペース)を付ける。
* Level 1 list item
** Level 2 list item
*** Level 3 list item
* Level 1 list item
番号ありリスト
順番つきの箇条書き。.
(ドットと半角スペース)を付ける。
. Level 1 list item
.. Level 2 list item
... Level 3 list item
. Level 1 list item
文字装飾
*strong*
で、strong (太字)
_cannot_
で、cannot(イタリック)
`OK`
で、OK
(モノスペース いわゆる、コードの一部を表示するときに使うやつ)
これらを組み合わせて使うことができる。
*_really_*
は、really(太字でイタリック)など。
//
を入れるとコメントに。
It has *strong* significance to me.
I _cannot_ stress this enough.
Type `OK` to accept.
That *_really_* has to go.
Can't pick one? Let's use them `*_all_*`.
// A single-line comment
#cinnamon#
でハイライト。
文字の途中でハイライトを入れる場合は、##Mark##up
のように、##
で囲む。
下線を引く場合は、[.underline]#cores#
取り消し線を引く場合は、[.line-through]#ten#
Werewolves are allergic to #cinnamon#.
##Mark##up refers to text that contains formatting ##mark##s.
Where did all the [.underline]#cores# go?
We need [.line-through]#ten# twenty VMs.
ソースコード
テーブルタイトルと同様、.Some Ruby code
のように、.タイトル
で、ソースコードのタイトルを付けることができる。
.Some Ruby code
[source,ruby]
----
require 'sinatra'
get '/hi' do
"Hello World!"
end
----
リンク
https://asciidoctor.org
のようにULRの部分に自動的にリンクが張られる。
また、[Asciidoctor]
は、[]
内に書かれたテキストで、ハイパーリンクになる。
https://asciidoctor.org - automatic!
https://asciidoctor.org[Asciidoctor]
補足説明
NOTE:
をつけると、気をつけたいポイントなどを目立たせて表示することができる。
そのほか、IMPORTANT:
、TIP:
、CAUTION:
、WARNING:
がある。
NOTE: An admonition draws the reader's attention to auxiliary information.
Here are the other built-in admonition types:
IMPORTANT: Don't forget the children!
TIP: Look for the warp zone under the bridge.
CAUTION: Slippery when wet.
WARNING: The software you're about to use is untested.
引用
[quote, 引用元]
のように、引用元を記載する。,
を入れると、次の行へ。
引用元のURLへリンクを載せる場合は、''
のようにシングルクウォートで囲む必要がある。
[quote, Charles Lutwidge Dodgson, 'Mathematician and author, also known as https://en.wikipedia.org/wiki/Lewis_Carroll[Lewis Carroll]']
____
If you don't know where you are going, any road will get you there.
____
目次の自動生成
目次、TOC(Table of Contents)を自動生成する。
ドキュメントのタイトル以下に、:toc:
を付けるだけ。
タイトルや、表示するセクションレベルなどは、カスタマイズできる。
例えば、:toclevels: 3
で、セクションレベル3までになる。(デフォルトはセクションレベル2。つまり===
まで表示される。)
また、:toc: left
で、TOCの場所を左側に配置できる。右側に配置したい場合は、leftをrightに置き換えればよい。
= Document Title
Doc Writer <doc.writer@email.org>
:toc:
:toclevels: 3
以下は、セクションレベル3までのヘッダに対して、目次を生成した例。
文中には、セクションレベル4まであるが、設定したセクションレベル3までしか目次が生成されていない。