asciidoc - thawk/wiki GitHub Wiki

asciidoc摘要

1. Text Formatting

1.1. Quoted Text

_Emphasized text_

Word phrases 'enclosed in single quote characters' (acute accents) or _underline characters_ are emphasized.

*Strong text*

Word phrases *enclosed in asterisk characters* are rendered in a strong font (usually bold).

+Monospaced text+

Word phrases `enclosed in backtick characters` (grave accents) or +plus characters+ are rendered in a monospaced font.

``Quoted text''

Phrases ``enclosed with two grave accents to the left and two acute accents to the right'' are rendered in ``quotation'' marks. Asciidoctor use ` inside ' or ", like "`sample text`": “sample text”

#highlight text#

Placing #hashes around text# render text as highlighed.

1.1.1. Constrained and Unconstrained Quotes

There are actually two types of quotes:

Constrained quotes

前后加空白字符

Unconstrained quotes

前后不需要有空白字符,但要`-, `*, +, `#`等字符要用两遍:

**F**ile Open...

File Open…​

1.2. 忽略格式,直接输出

+++Triple-plus passthrough\+\++

原样输出

$$Double-dollar passthrough$$

只替换特殊字符(Special characters). This passthrough can be prefixed with inline attributes.

1.3. 上标和下标

^上标\^

这是上标

~下标\~

这是下标

1.4. 换行符

行末一个加号再加一个以上的空格会在HTML输出中增加<br />。在DocBook输出中无效。

1.5. 字符替换

(C) copyright

© copyright

(TM) trademark

™ trademark

(R) registered trademark

® registered trademark

-- em dash

 — em dash

... ellipsis
  1. ellipsis

-> right arrow

→ right arrow

<- left arrow

← left arrow

=> right double arrow

⇒ right double arrow

<= left double arrow

⇐ left double arrow

2. 标题

2.1. 两行标题

由一行标题,跟着一行重复的字符形成。

Level 0 (top level):     ======================
Level 1:                 ----------------------
Level 2:                 ~~~~~~~~~~~~~~~~~~~~~~
Level 3:                 ^^^^^^^^^^^^^^^^^^^^^^
Level 4 (bottom level):  ++++++++++++++++++++++

两行标题对中文支持不好,推荐用单行标题

2.2. 单行标题

行首和行末都是相同数目的等号。等号的数量决定标题级别。后面的等号可以忽略

= Document Title (level 0) =
== Section title (level 1) ==
=== Section title (level 2) ===
==== Section title (level 3) ====
===== Section title (level 4) =====

3. 块标题

行首是小数点,后面跟标题

.Notes
- Note 1.
- Note 2.

is rendered as:

Notes
  • Note 1.

  • Note 2.

4. 键盘宏

需要打开experimental属性。

// We must enable experimental attribute.
:experimental:

  可以定义自己的键名(如MacOS的Command键)

// Define unicode for Apple Command key.
:commandkey: &#8984;

使用

Press kbd:[{commandkey} + 1] or kbd:[Ctrl + 1]

5. BlockId

在双重方括号中包含块的名字,用于以后进行引用。

[[chapter-titles]]
Chapter titles can be ...

后面可以用 <<chapter-titles,chapter titles>> 来引用上面的块

6. 段落

段落结束于空行、文件尾或DelimitedBlock

6.1. 缺省段落

由多个非空行文本组成。首行必须顶格

verse风格可以保留行四周的边框

缺省段落,
第二行。

[verse]
带**verse**风格的缺省段落,
第二行。

Renders:

缺省段落, 第二行。

verse风格的缺省段落,
第二行。

6.2. Literal段落

由多个非空行文本组成。首行缩进1或多个空格。 段落中的格式字符将保持原样。

    **Literal**缺省段落,
    第二行。

Renders:

**Literal**缺省段落,
第二行。

6.3. Admonition段落

段首为 NOTE:, TIP:, IMPORTANT:, WARNING: or CAUTION:

或段前加上一行[NOTE] [TIP] [IMPORTANT] [WARNING] [CAUTION]

NOTE: This is an example note.

or the alternative syntax:

[NOTE]
  This is an example note.

Renders:

Note
This is an example note.

7. Delimited Blocks

7.1. Predefined Delimited Blocks

CommentBlock:     //////////////////////////
PassthroughBlock: ++++++++++++++++++++++++++
ListingBlock:     --------------------------
LiteralBlock:     ..........................
SidebarBlock:     **************************
QuoteBlock:       __________________________
ExampleBlock:     ==========================
Filter blocks:    ~~~~~~~~~~~~~~~~~~~~~~~~~~
Default DelimitedBlock substitutions

`-------------.------------.---------.---------.---------.--------- Passthrough Listing Literal Sidebar Quote

Callouts        No          Yes       Yes       No        No
Attributes      Yes         No        No        Yes       Yes
Inline Macros   Yes         No        No        Yes       Yes
Quotes          No          No        No        Yes       Yes
Replacements    No          No        No        Yes       Yes
Special chars   No          Yes       Yes       Yes       Yes
Special words   No          No        No        Yes       Yes
Note

可以通过加上[subs="quotes"]之类,让一个block支持更多的格式。

8. source块

\[source,lang,src_numbered,src_tab]

有三个位置属性,分别是语言(cpp/python/sh等)、是否显示行号、源文件的 制表符位置。

9. asciidoctor.js toc

  • 需要使用:toc: macro属性,并且在适当位置用toc::[]指出toc的放置位置

  • 模板

    = asciidoc摘要
    :numbered:
    :toc: macro
    :toc-title: 目录
    
    toc::[]
  • 可能需要使用BOM才可以在asciidoctor.js live preview中显示中文

10. 表格

10.1. 自动宽度

[%autowidth]
[options="autowidth"]

10.2. 跨越多行、多列

rowspan
+2|cell
colspan
2+|cell

10.3. 指定列的格式

[cols="e,a,m"]
e

emphasized

a

Asciidoc markup

m

monospace

h

header style, all column values are styled as header

s

strong

l

literal, text is shown in monospace font and line breaks are kept

d

default

v

verse, keeps line breaks

11. asciidoctor相关技巧

11.1. docinfo

可以注入CSS内容。

Mode Location Behaviour Docinfo file name

Private

Head

Adds content to <head>/<info> for <docname>.adoc files.

<docname>-docinfo<outfilesuffix>

Footer

Adds content to end of document for <docname>.adoc files.

<docname>-docinfo-footer<outfilesuffix>

Shared

Head

Adds content to <head>/<info> for any document in same directory.

docinfo<outfilesuffix>

Footer

Adds content to end of document for any document in same directory.

docinfo-footer<outfilesuffix>

docinfo属性
  • private-head

  • private-footer

  • private (alias for private-head,private-footer)

  • shared-head

  • shared-footer

  • shared (alias for shared-head,shared-footer)

docinfodir属性

指定docinfo的路径

11.2. 支持diagram

  1. 安装asciidoctor-diagram

  2. 调用时加上-r asciidoctor-diagram参数

    asciidoctor -r asciidoctor-diagram graphviz.asciidoc

如果需要 cisco.router 等图片,需要安装 py27-blockdiagcontrib-cisco

12. reveal.js backend

安装
sudo gem install asciidoctor slim thread_safe
sudo gem install bundler
对于每个演示
  1. Create project directory

    mkdir my-awesome-presentation
    cd my-awesome-presentation
  2. Create a file named Gemfile with the following content:

    source 'https://rubygems.org'
    
    gem 'asciidoctor-revealjs' # latest released version
    #gem 'asciidoctor-revealjs', github: 'asciidoctor/asciidoctor-reveal.js' # github master branch
    Note
    For some reason, when you use the system Ruby on Fedora, you also have to add the json gem to the Gemfile.
  3. Install the gems into the project

    bundle config --local github.https true
    bundle --path=.bundle/gems --binstubs=.bundle/.bin
  4. Optional: Copy or clone reveal.js presentation framework. Allows you to modify themes or view slides offline.

    git clone -b 3.3.0 --depth 1 https://github.com/hakimel/reveal.js.git
  5. 创建演示文件

    bundle exec asciidoctor-revealjs CONTENT_FILE.adoc
⚠️ **GitHub.com Fallback** ⚠️