AsciiDoc 语法快速参考

此页面上的示例演示了内置 HTML 转换器生成的输出。Asciidoc 转换器在生成 PDF、EPUB 和 DocBook 等其他输出格式时,预期会产生互补的输出。

段落

示例 1. 段落
Paragraphs don't require special markup in AsciiDoc.
A paragraph is defined by one or more consecutive lines of text.
Line breaks within a paragraph are not displayed.

Leave at least one empty line to begin a new paragraph.
查看 示例 1 的结果

在 AsciiDoc 中,段落不需要特殊标记。段落由一个或多个连续的文本行定义。段落内的换行符不会显示。

留出至少一个空行以开始一个新段落。

示例 2. 字面段落
A normal paragraph.

 A literal paragraph.
 One or more consecutive lines indented by at least one space.

 The text is shown in a fixed-width (typically monospace) font.
 The lines are preformatted (i.e., as formatted in the source).
 Spaces and newlines,
 like the ones in this sentence,
 are preserved.
查看 示例 2 的结果

一个普通段落。

A literal paragraph.
One or more consecutive lines indented by at least one space.
The text is shown in a fixed-width (typically monospace) font.
The lines are preformatted (i.e., as formatted in the source).
Spaces and newlines,
like the ones in this sentence,
are preserved.
示例 3. 硬换行
Roses are red, +
violets are blue.

[%hardbreaks]
A ruby is red.
Java is black.
查看 示例 3 的结果

玫瑰是红色的,
紫罗兰是蓝色的。

红宝石是红色的。
Java 是黑色的。

示例 4. 引言段落
[.lead]
This text will be styled as a lead paragraph (i.e., larger font).

This paragraph will not be.
查看 示例 4 的结果

此文本将被样式化为引言段落(即,字体较大)。

此段落不会。

如果引言段落上没有指定角色,则默认的 Asciidoctor 样式会自动将序言的第一段样式化为引言段落

文本格式化

示例 5. 受限粗体、斜体和等宽字体
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_*`.
查看 示例 5 的结果

这对我很**重要**。

我**强调**这一点也不为过。

键入 OK 即可接受。

那**_真的_**得走了。

选不出来?我们****用上吧。

示例 6. 非受限粗体、斜体和等宽字体
**C**reate, **R**ead, **U**pdate, and **D**elete (CRUD)

That's fan__freakin__tastic!

Don't pass generic ``Object``s to methods that accept ``String``s!

It was Beatle**__mania__**!
查看 示例 6 的结果

**C**reate, **R**ead, **U**pdate, and **D**elete (CRUD)

那太棒了!

不要将通用 Object 传递给接受 String 的方法!

那是一场甲壳虫**狂潮**!

示例 7. 高亮、下划线、删除线和自定义角色
Mark my words, #automation is essential#.

##Mark##up refers to text that contains formatting ##mark##s.

Where did all the [.underline]#cores# go?

We need [.line-through]#ten# twenty VMs.

A [.myrole]#custom role# must be fulfilled by the theme.
查看 示例 7 的结果

我说了,自动化是必不可少的

标记 指的是包含格式标记的文本。

所有的内核都去哪儿了?

我们需要十个二十台虚拟机。

一个自定义角色必须由主题来满足。

示例 8. 上标和下标
^super^script

~sub~script
查看 示例 8 的结果

上标

下标

示例 9. 智能引号和撇号
"`double curved quotes`"

'`single curved quotes`'

Olaf's desk was a mess.

A ``std::vector```'s size is the number of items it contains.

All of the werewolves`' desks were a mess.

Olaf had been with the company since the `'00s.
查看 示例 9 的结果

“双弯引号”

‘单弯引号’

奥拉夫的桌子很乱。

std::vector 的大小是它包含的项的数量。

所有的狼人的桌子都很乱。

奥拉夫自 ’00 年代起就一直在这家公司工作。

示例 10. 自动链接、URL 宏和 mailto 宏
https://asciidoctor.org.cn - automatic!

https://asciidoctor.org.cn[Asciidoctor]

devel@discuss.example.org

mailto:devel@discuss.example.org[Discuss]

mailto:join@discuss.example.org[Subscribe,Subscribe me,I want to join!]
查看 示例 10 的结果
示例 11. 带属性的 URL 宏
https://chat.asciidoc.org[Discuss AsciiDoc,role=external,window=_blank]

https://chat.asciidoc.org[Discuss AsciiDoc^]
查看 示例 11 的结果
当目标以 https: 等 URL 方案开头时,*不*需要 link: 宏前缀。URL 方案充当隐式宏前缀。
如果链接文本包含逗号,并且文本后面跟有一个或多个命名属性,则必须将文本括在双引号中。否则,文本将在逗号处被截断(剩余文本将被拉入属性解析)。
示例 12. 带空格和特殊字符的 URL
link:++https://example.org/?q=[a b]++[URL with special characters]

https://example.org/?q=%5Ba%20b%5D[URL with special characters]
示例 13. 链接到相对文件
link:index.html[Docs]
示例 14. 使用 Windows UNC 路径进行链接
link:\\server\share\whitepaper.pdf[Whitepaper]
示例 15. 行内锚点
[[bookmark-a]]Inline anchors make arbitrary content referenceable.

[#bookmark-b]#Inline anchors can be applied to a phrase like this one.#

anchor:bookmark-c[]Use a cross reference to link to this location.

[[bookmark-d,last paragraph]]The xreflabel attribute will be used as link text in the cross-reference link.
示例 16. 交叉引用
See <<paragraphs>> to learn how to write paragraphs.

Learn how to organize the document into <<section-titles,sections>>.
查看 示例 16 的结果

参见 段落,了解如何编写段落。

了解如何将文档组织成

示例 17. 文档间交叉引用
Refer to xref:document-b.adoc#section-b[Section B of Document B] for more information.

If you never return from xref:document-b.adoc[Document B], we'll send help.

文档头

文档头是可选的。它可能不包含任何空行,并且必须与内容之间至少有一个空行分隔。

示例 18. 标题
= Document Title

This document provides...
示例 19. 标题和作者行
= Document Title
Author Name <author@email.org>

This document provides...
示例 20. 标题、作者行和修订行
= Document Title
Author Name <author@email.org>; Another Author <a.author@email.org>
v2.0, 2019-03-22

This document provides...
你不能在没有作者行的情况下拥有修订行
示例 21. 带有属性条目的文档头
= Document Title
Author Name <author@email.org>
v2.0, 2019-03-22
:toc:
:homepage: https://example.org

This document provides...

节标题

当文档类型为 article(默认)时,文档只能有一个 0 级节标题(=),即文档标题(doctitle)。

示例 22. 文章节级别
= Document Title (Level 0)

== Level 1 Section Title

=== Level 2 Section Title

==== Level 3 Section Title

===== Level 4 Section Title

====== Level 5 Section Title

== Another Level 1 Section Title
查看 示例 22 的结果

文档标题(0 级)

1 级节标题

2 级节标题

3 级节标题

4 级节标题
5 级节标题

另一个 1 级节标题

book 文档类型可以有额外的 0 级节标题,这些标题被解释为部分。存在至少一个部分会隐式地将文档视为多部分书籍。

示例 23. 书籍节级别
= Document Title (Level 0)

== Level 1 Section Title

= Level 0 Section Title (Part)

== Level 1 Section Title

=== Level 2 Section Title

==== Level 3 Section Title

===== Level 4 Section Title

====== Level 5 Section Title

= Another Level 0 Section Title (Part)
示例 24. 离散标题(非节)
[discrete]
=== I'm an independent heading!

This paragraph is its sibling, not its child.
查看 示例 24 的结果

我是一个独立的标题!

这个段落是它的同级,而不是它的子级。

自动目录

示例 25. 为文档激活目录
= Document Title
Doc Writer <doc.writer@email.org>
:toc:

目录的标题显示的节深度位置都可以自定义。

包含

示例 26. 包含文档部分
= Reference Documentation
Lead Developer

This is documentation for project X.

include::basics.adoc[]

include::installation.adoc[]

include::example.adoc[]
示例 27. 通过标记区域或行包含内容
include::filename.txt[tag=definition]

include::filename.txt[lines=5..10]
示例 28. 从 URL 包含内容
include::https://raw.githubusercontent.com/asciidoctor/asciidoctor/main/README.adoc[]
从 URL 包含内容可能存在危险,因此如果安全模式为 SECURE 或更高,则会禁用它。假设安全模式低于 SECURE,您还必须设置 allow-uri-read 属性以允许 AsciiDoc 处理器从 URL 读取内容。

列表

示例 29. 无序列表
* List item
** Nested list item
*** Deeper nested list item
* List item
 ** Another nested list item
* List item
查看 示例 29 的结果
  • 列表项

    • 嵌套列表项

      • 更深层嵌套的列表项

  • 列表项

    • 另一个嵌套列表项

  • 列表项

列表前后需要一个空行才能将其与其他块分隔。您可以通过在第二个列表上方添加一个空的属性列表(即 [])或在第一个列表后插入一个空行后跟一个行注释来强制两个相邻的列表分开。如果您使用行注释,约定是使用 //- 来提示其他作者它作为列表分隔符。
示例 30. 无序列表最大嵌套级别
* Level 1 list item
** Level 2 list item
*** Level 3 list item
**** Level 4 list item
***** Level 5 list item
****** etc.
* Level 1 list item
查看 示例 30 的结果
  • 1 级列表项

    • 2 级列表项

      • 3 级列表项

        • 4 级列表项

          • 5 级列表项

            • 等等。

  • 1 级列表项

可以使用列表样式(例如 square)更改无序列表标记

示例 31. 有序列表
. Step 1
. Step 2
.. Step 2a
.. Step 2b
. Step 3
查看 示例 31 的结果
  1. 步骤 1

  2. 步骤 2

    1. 步骤 2a

    2. 步骤 2b

  3. 步骤 3

示例 32. 有序列表最大嵌套级别
. Level 1 list item
.. Level 2 list item
... Level 3 list item
.... Level 4 list item
..... Level 5 list item
. Level 1 list item
查看 示例 32 的结果
  1. 1 级列表项

    1. 2 级列表项

      1. 3 级列表项

        1. 4 级列表项

          1. 5 级列表项

  2. 1 级列表项

有序列表支持编号样式,例如 lowergreekdecimal-leading-zero

示例 33. 检查列表
* [*] checked
* [x] also checked
* [ ] not checked
* normal list item
查看 示例 33 的结果
  • 已勾选

  • 也已勾选

  • 未勾选

  • 普通列表项

示例 34. 定义列表
First term:: The description can be placed on the same line
as the term.
Second term::
Description of the second term.
The description can also start on its own line.
查看 示例 34 的结果
第一个术语

描述可以放在术语的同一行上。

第二个术语

第二个术语的描述。描述也可以开始在新的一行。

示例 35. 问题和答案列表
[qanda]
What is the answer?::
This is the answer.

Are cameras allowed?::
Are backpacks allowed?::
No.
查看 示例 35 的结果
  1. 答案是什么?

    这就是答案。

  2. 允许带相机吗?

    允许带背包吗?

    不可以。

示例 36. 混合
Operating Systems::
  Linux:::
    . Fedora
      * Desktop
    . Ubuntu
      * Desktop
      * Server
  BSD:::
    . FreeBSD
    . NetBSD

Cloud Providers::
  PaaS:::
    . OpenShift
    . CloudBees
  IaaS:::
    . Amazon EC2
    . Rackspace
查看 示例 36 的结果
操作系统
Linux
  1. Fedora

    • 桌面

  2. Ubuntu

    • 桌面

    • 服务器

BSD
  1. FreeBSD

  2. NetBSD

云提供商
PaaS
  1. OpenShift

  2. CloudBees

IaaS
  1. Amazon EC2

  2. Rackspace

列表可以缩进。前导空格不重要。
示例 37. 大纲列表中的复杂内容
* Every list item has at least one paragraph of content,
  which may be wrapped, even using a hanging indent.
+
Additional paragraphs or blocks are adjoined by putting
a list continuation on a line adjacent to both blocks.
+
list continuation:: a plus sign (`{plus}`) on a line by itself

* A literal paragraph does not require a list continuation.

 $ cd projects/my-book

* AsciiDoc lists may contain any compound content.
+
|===
|Column 1, Header Row |Column 2, Header Row

|Column 1, Row 1
|Column 2, Row 1
|===
查看 示例 37 的结果
  • 每个列表项至少有一个段落内容,可以换行,甚至可以使用悬挂缩进。

    附加的段落或块通过在与两个块相邻的行上放置列表延续来连接。

    列表延续

    单独一行的加号 (+)

  • 字面段落不需要列表延续。

    $ cd projects/my-book
  • AsciiDoc 列表可以包含任何复合内容。

    第 1 列,标题行 第 2 列,标题行

    第 1 列,第 1 行

    第 2 列,第 1 行

图片

您可以使用imagesdir 属性来避免在每个图像宏中硬编码图像的常见路径。此属性的值可以是绝对路径、相对路径或基本 URL。如果图像目标是相对路径,则该属性的值将被预置(即,相对于 imagesdir 属性的值解析)。如果图像目标是 URL 或绝对路径,则该属性的值*不会*被预置。

示例 38. 块图像宏
image::sunset.jpg[]

image::sunset.jpg[Sunset]

.A mountain sunset
[#img-sunset,caption="Figure 1: ",link=https://www.flickr.com/photos/javh/5448336655]
image::macros:sunset.jpg[Sunset,200,100]

image::https://asciidoctor.org.cn/images/octocat.jpg[GitHub mascot]
查看 示例 38 的结果
sunset
Sunset
Sunset
图 1:山景日落
GitHub mascot

宏中图像关键字后面的两个冒号(即 image::)表示块图像(也称为图形),而图像关键字后面的一个冒号(即 image:)表示行内图像。(所有宏都遵循此模式)。当您需要在文本行中放置图像时,可以使用行内图像。否则,您应该优先使用块形式。

示例 39. 行内图像宏
Click image:play.png[] to get the party started.

Click image:pause.png[title=Pause] when you need a break.
查看 示例 39 的结果

点击 play 开始派对。

休息时,请点击 pause

示例 40. 带有定位角色的行内图像宏
image:sunset.jpg[Sunset,150,150,role=right] What a beautiful sunset!
查看 示例 40 的结果

Sunset 多么美丽的日落!

示例 41. 嵌入
= Document Title
:data-uri:

当设置 data-uri 属性时,文档中的所有图像(包括劝告图标)都将作为数据 URI嵌入到文档中。您也可以使用 -a data-uri 作为命令行参数传递它。

音频

示例 42. 块音频宏
audio::ocean-waves.wav[]

audio::ocean-waves.wav[start=60,opts=autoplay]

您可以通过宏上的其他属性和选项来控制音频设置。

视频

示例 43. 块视频宏
video::video-file.mp4[]

video::video-file.mp4[width=640,start=60,opts=autoplay]
示例 44. 嵌入式 YouTube 视频
video::RvRhUHTV_8k[youtube]
示例 45. 嵌入式 Vimeo 视频
video::67480300[vimeo]

您可以通过宏上的其他属性和选项来控制视频设置。

键盘、按钮和菜单宏

您必须在文档头中设置 experimental 属性才能启用这些宏。
示例 46. 键盘宏
|===
|Shortcut |Purpose

|kbd:[F11]
|Toggle fullscreen

|kbd:[Ctrl+T]
|Open a new tab
|===
查看 示例 46 的结果
快捷键 目的

F11

切换全屏

Ctrl+T

打开新标签页

示例 47. 菜单宏
To save the file, select menu:File[Save].

Select menu:View[Zoom > Reset] to reset the zoom level to the default setting.
查看 示例 47 的结果

要保存文件,请选择 文件  保存

要将缩放级别重置为默认设置,请选择 视图  缩放  重置

示例 48. 按钮宏
Press the btn:[OK] button when you are finished.

Select a file in the file navigator and click btn:[Open].
查看 示例 48 的结果

完成后,请按 确定 按钮。

在文件导航器中选择一个文件,然后单击 打开

字面量和源代码

示例 49. 行内字面量等宽字体
Output literal monospace text, such as `+{backtick}+` or `+https://:8080+`, by enclosing the text in a pair of pluses surrounded by a pair of backticks.
查看 示例 49 的结果

输出字面等宽文本,例如 {backtick}https://:8080,方法是将文本用一对由一对反引号包围的加号括起来。

示例 50. 字面段落
Normal line.

 Indent line by one space to create a literal line.

Normal line.
查看 示例 50 的结果

普通行。

Indent line by one space to create a literal line.

普通行。

示例 51. 字面块
....
error: 1954 Forbidden search
absolutely fatal: operation lost in the dodecahedron of doom

Would you like to try again? y/n
....
查看 示例 51 的结果
error: 1954 Forbidden search
absolutely fatal: operation lost in the dodecahedron of doom

Would you like to try again? y/n
示例 52. 带标题的列表块
.Gemfile.lock
----
GEM
  remote: https://rubygems.org.cn/
  specs:
    asciidoctor (2.0.15)

PLATFORMS
  ruby

DEPENDENCIES
  asciidoctor (~> 2.0.15)
----
查看 示例 52 的结果
列表 1. Gemfile.lock
GEM
  remote: https://rubygems.org.cn/
  specs:
    asciidoctor (2.0.15)

PLATFORMS
  ruby

DEPENDENCIES
  asciidoctor (~> 2.0.15)
示例 53. 带标题和语法高亮的源代码块
.Some Ruby code
[source,ruby]
----
require 'sinatra'

get '/hi' do
  "Hello World!"
end
----
查看 示例 53 的结果
列表 1. 一些 Ruby 代码
require 'sinatra'

get '/hi' do
  "Hello World!"
end

您必须通过在文档头、CLI 或 API 中设置 source-highlighter 属性来启用源代码高亮

:source-highlighter: rouge

请参阅语法高亮,了解使用 Asciidoctor 时接受哪些值。

示例 54. 带注释的源代码块
[source,ruby]
----
require 'sinatra' // <1>

get '/hi' do // <2>
  "Hello World!" // <3>
end
----
<1> Library import
<2> URL mapping
<3> HTTP response body
查看 示例 54 的结果
require 'sinatra' (1)

get '/hi' do (2)
  "Hello World!" (3)
end
1 库导入
2 URL 映射
3 HTTP 响应正文
示例 55. 使注释不可选
----
line of code // <1>
line of code # <2>
line of code ;; <3>
line of code <!--4-->
----
<1> A callout behind a line comment for C-style languages.
<2> A callout behind a line comment for Ruby, Python, Perl, etc.
<3> A callout behind a line comment for Clojure.
<4> A callout behind a line comment for XML or SGML languages like HTML.
查看 示例 55 的结果
line of code (1)
line of code (2)
line of code (3)
line of code (4)
1 C 风格语言的行注释后的注释。
2 Ruby、Python、Perl 等语言的行注释后的注释。
3 Clojure 的行注释后的注释。
4 HTML 等 XML 或 SGML 语言的行注释后的注释。
示例 56. 从文件包含的源代码块内容
[,ruby]
----
include::app.rb[]
----
示例 57. 从源目录相对文件包含的源代码块内容
:sourcedir: src/main/java

[source,java]
----
include::{sourcedir}/org/asciidoctor/Asciidoctor.java[]
----
示例 58. 从部分文件内容中剥离前导缩进
[source,ruby]
----
include::lib/app.rb[tag=main,indent=0]
----

当通过标记区域包含源代码时,经常使用indent 属性。它可以在 include 指令本身或包含的字面块、列表块或源代码块上指定。

当缩进为 0 时,会剥离前导块缩进。

当缩进大于 0 时,首先会剥离前导块缩进,然后块会根据此值指定的列数进行缩进。

示例 59. 源代码段落(无空行)
[source,xml]
<meta name="viewport"
  content="width=device-width, initial-scale=1.0">

This is normal content.
查看 示例 59 的结果
<meta name="viewport"
  content="width=device-width, initial-scale=1.0">

这是普通内容。

劝告

示例 60. 劝告段落
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.

IMPORTANT: Sign off before stepping away from your computer.
查看 示例 60 的结果
劝告能引起读者对辅助信息的注意。

这里是其他内置的劝告类型

别忘了孩子!
在桥下寻找传送带。
潮湿时湿滑。
您即将使用的软件未经测试。
离开电脑前请签离。
示例 61. 劝告块
[NOTE]
====
An admonition block may contain compound content.

.A list
- one
- two
- three

Another paragraph.
====
查看 示例 61 的结果

劝告块可以包含复合内容。

一个列表

另一个段落。

更多分隔块

任何块都可以有标题。块标题是通过在块上方开始于点的文本行定义的。该点后面不能跟空格。对于块图像,标题显示在块下方。对于所有其他块,标题通常显示在它上方。

示例 62. 侧边栏块
.Optional Title
****
Sidebars are used to visually separate auxiliary bits of content
that supplement the main text.
****
查看 示例 62 的结果
可选标题

侧边栏用于在视觉上分隔补充主要文本的辅助内容。

示例 63. 示例块
====
Here's a sample AsciiDoc document:

----
= Title of Document
Doc Writer
:toc:

This guide provides...
----

The document header is useful, but not required.
====
查看 示例 63 的结果

这是一个示例 AsciiDoc 文档

= Title of Document
Doc Writer
:toc:

This guide provides...

文档头很有用,但不是必需的。

示例 64. 块引用
[quote,Abraham Lincoln,Address delivered at the dedication of the Cemetery at Gettysburg]
____
Four score and seven years ago our fathers brought forth
on this continent a new nation...
____

[quote,Albert Einstein]
A person who never made a mistake never tried anything new.

____
A person who never made a mistake never tried anything new.
____

[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.
____

"I hold it that a little rebellion now and then is a good thing,
and as necessary in the political world as storms in the physical."
-- Thomas Jefferson, Papers of Thomas Jefferson: Volume 11
查看 示例 64 的结果

四分之二年前,我们的祖先在这片大陆上建立了一个新国家……

— 亚伯拉罕·林肯
在葛底斯堡公墓落成典礼上的演讲
一个从未犯过错误的人,从未尝试过新事物。
— 阿尔伯特·爱因斯坦

一个从未犯过错误的人,从未尝试过新事物。

如果你不知道你要去哪里,任何一条路都会带你到那里。

— 查尔斯·勒特维奇·道奇森
数学家和作家,又名刘易斯·卡罗尔
我认为偶尔的小规模叛乱是件好事,在政治世界中与物理世界中的风暴一样有必要。
— 托马斯·杰斐逊
托马斯·杰斐逊论文:第 11 卷
示例 65. 开放块
--
An open block can be an anonymous container,
or it can masquerade as any other block.
--

[source]
--
puts "I'm a source block!"
--
查看 示例 65 的结果

一个开放块可以是一个匿名的容器,也可以伪装成任何其他块。

puts "I'm a source block!"
示例 66. 直通块
++++
<p>
Content in a passthrough block is passed to the output unprocessed.
That means you can include raw HTML, like this embedded Gist:
</p>

<script src="https://gist.github.com/mojavelinux/5333524.js">
</script>
++++
查看 示例 66 的结果

直通块中的内容将未经处理地传递到输出。这意味着您可以包含原始 HTML,例如此嵌入的 Gist

示例 67. 自定义块替换
:release-version: 2.4.3

[source,xml,subs=attributes+]
----
<dependency>
  <groupId>org.asciidoctor</groupId>
  <artifactId>asciidoctorj</artifactId>
  <version>{release-version}</version>
</dependency>
----
查看 示例 67 的结果
<dependency>
  <groupId>org.asciidoctor</groupId>
  <artifactId>asciidoctorj</artifactId>
  <version>2.4.3</version>
</dependency>

表格

示例 68. 带标题、两列、标题行和两行内容的表格
.Table Title
|===
|Column 1, Header Row |Column 2, Header Row (1)
(2)
|Cell in column 1, row 1
|Cell in column 2, row 1

|Cell in column 1, row 2
|Cell in column 2, row 2
|===
1 除非指定了 cols 属性,否则列数等于第一行(非空行)的单元格分隔符数量。
2 当表格开头的一个非空行后紧跟着一个空行时,第一行中的单元格将被提升为表头。
查看 示例 68 的结果
表 1. 表格标题
第 1 列,标题行 第 2 列,标题行

第 1 列,第 1 行的单元格

第 2 列,第 1 行的单元格

第 1 列,第 2 行的单元格

第 2 列,第 2 行的单元格

示例 69. 带两列、标题行和两行内容的表格
[%header,cols=2*] (1)
|===
|Name of Column 1
|Name of Column 2

|Cell in column 1, row 1
|Cell in column 2, row 1

|Cell in column 1, row 2
|Cell in column 2, row 2
|===
1 cols 属性中的 * 是重复运算符。它表示将列规范重复到剩余的列。在这种情况下,我们将默认格式重复到 2 列。当标题行中的单元格未在单行上定义时,您必须使用 cols 属性设置表格的列数以及 %header 选项(或 options=header 属性)将第一行提升为表头。
查看 示例 69 的结果
第 1 列名称 第 2 列名称

第 1 列,第 1 行的单元格

第 2 列,第 1 行的单元格

第 1 列,第 2 行的单元格

第 2 列,第 2 行的单元格

示例 70. 带三列、标题行和两行内容的表格
.Applications
[cols="1,1,2"] (1)
|===
|Name |Category |Description

|Firefox
|Browser
|Mozilla Firefox is an open source web browser.
It's designed for standards compliance,
performance, portability.

|Arquillian
|Testing
|An innovative and highly extensible testing platform.
Empowers developers to easily create real, automated tests.
|===
1 在此示例中,cols 属性有两个功能。它指定此表格有三列,并设置它们的相对宽度。
查看 示例 70 的结果
表 1. 应用程序
名称 类别 描述

Firefox

浏览器

Mozilla Firefox 是一款开源网页浏览器。它专为标准合规性、性能和可移植性而设计。

Arquillian

测试

一个创新且高度可扩展的测试平台。使开发人员能够轻松创建真实的自动化测试。

示例 71. 包含 AsciiDoc 内容的列的表格
[cols="2,2,5a"]
|===
|Firefox
|Browser
|Mozilla Firefox is an open source web browser.

It's designed for:

* standards compliance
* performance
* portability

https://getfirefox.com[Get Firefox]!
|===
查看 示例 71 的结果

Firefox

浏览器

Mozilla Firefox 是一款开源网页浏览器。

它专为

  • 标准合规性

  • 性能

  • 可移植性

示例 72. 使用简写法的 CSV 数据表
,===
Artist,Track,Genre

Baauer,Harlem Shake,Hip Hop
,===
查看 示例 72 的结果
艺术家 曲目 流派

Baauer

Harlem Shake

嘻哈

示例 73. CSV 数据表
[%header,format=csv]
|===
Artist,Track,Genre
Baauer,Harlem Shake,Hip Hop
The Lumineers,Ho Hey,Folk Rock
|===
查看 示例 73 的结果
艺术家 曲目 流派

Baauer

Harlem Shake

嘻哈

Lumineers

Ho Hey

民谣摇滚

示例 74. 从文件包含的 CSV 数据表
,===
include::customers.csv[]
,===
示例 75. 使用简写法的 DSV 数据表
:===
Artist:Track:Genre

Robyn:Indestructible:Dance
:===
查看 示例 75 的结果
艺术家 曲目 流派

Robyn

Indestructible

舞曲

示例 76. 带格式、对齐和合并单元格的表格
[cols="e,m,^,>s",width="25%"]
|===
|1 >s|2 |3 |4
^|5 2.2+^.^|6 .3+<.>m|7
^|8
|9 2+>|10
|===
查看 示例 76 的结果

1

2

3

4

5

6

7

8

9

10

ID、角色和选项

示例 77. 为块 ID(锚点)和角色分配的简写方法
[#goals.incremental]
* Goal 1
* Goal 2
  • 要使用简写语法指定多个角色,请用点分隔它们。

  • idrole 值在简写语法中的顺序无关紧要。

示例 78. 为块 ID(锚点)和角色分配的正式方法
[id="goals",role="incremental"]
* Goal 1
* Goal 2
示例 79. 显式节 ID(锚点)
[#null-values]
== Primitive types and null values
示例 80. 为行内格式化文本分配 ID(锚点)和角色
[#id-name.role-name]`monospace text`

[#free-world.goals]*free the world*
示例 81. 为块选项分配的简写方法
[%header%footer%autowidth]
|===
|Header A |Header B
|Footer A |Footer B
|===
示例 82. 为块选项分配的正式方法
[options="header,footer,autowidth"]
|===
|Header A |Header B
|Footer A |Footer B
|===

// options can be shorted to opts
[opts="header,footer,autowidth"]
|===
|Header A |Header B
|Footer A |Footer B
|===

注释

示例 83. 行注释和块注释
// A single-line comment

////
A multi-line comment.

Notice it's a delimited block.
////

换行符

示例 84. 主题分隔符(也称为水平线)
before

'''

after
查看 示例 84 的结果

之前


之后

示例 85. 分页符
<<<

属性和替换

示例 86. 属性声明和用法
:url-home: https://asciidoctor.org.cn
:link-docs: https://asciidoctor.org.cn/docs[documentation]
:summary: AsciiDoc is a mature, plain-text document format for \
       writing notes, articles, documentation, books, and more. \
       It's also a text processor & toolchain for translating \
       documents into various output formats (i.e., backends), \
       including HTML, DocBook, PDF and ePub.
:checkedbox: pass:normal[{startsb}&#10004;{endsb}]

Check out {url-home}[Asciidoctor]!

{summary}

Be sure to read the {link-docs} too!

{checkedbox} That's done!
查看 示例 86 的结果

看看Asciidoctor

AsciiDoc 是一种成熟的纯文本文档格式,用于编写笔记、文章、文档、书籍等。它也是一种文本处理器和工具链,用于将文档翻译成各种输出格式(即后端),包括 HTML、DocBook、PDF 和 ePub。

一定要阅读文档

[✔] 完成!

要了解有关可用属性和替换组的更多信息,请参阅

示例 87. 计数器属性
.Parts{counter2:index:0}
|===
|Part Id |Description

|PX-{counter:index}
|Description of PX-{index}

|PX-{counter:index}
|Description of PX-{index}
|===
查看 示例 87 的结果
表 1. 部件
部件 ID 描述

PX-1

PX-1 的描述

PX-2

PX-2 的描述

文本替换

文本符号替换
名称 语法 Unicode 替换 渲染 注释

版权

(C)

&#169;

©

注册

(R)

&#174;

®

商标

(TM)

&#8482;

长破折号

--

&#8212;

 — 

仅当介于两个单词字符之间、单词字符和行边界之间,或被空格包围时才替换。

当被空格包围时(例如 a -- b),普通空格会被窄空格(&#8201;)替换。否则,长破折号后会有一个零宽空格(&#8203;)以提供断开机会。

省略号

...

&#8230;

…​

省略号后会有一个零宽空格(&#8203;)以提供断开机会。

单右箭头

->

&#8594;

双右箭头

=>

&#8658;

单左箭头

<-

&#8592;

双左箭头

<=

&#8656;

印刷体撇号

Sam's

Sam&#8217;s

Sam’s

打字机撇号将被替换为印刷体(也称为弯曲或智能)撇号。

任何命名、数字或十六进制XML 字符引用都受支持。

转义替换

示例 88. 反斜杠
In /items/\{id}, the id attribute isn't replaced.
The curly braces around it are preserved.

\*Stars* isn't displayed as bold text.
The asterisks around it are preserved.

\&sect; appears as an entity reference.
It's not converted into the section symbol (&#167;).

\=> The backslash prevents the equals sign followed by a greater
than sign from combining to form a double arrow character (=>).

\[[Word]] is not interpreted as an anchor.
The double brackets around it are preserved.

[\[[Word]]] is not interpreted as a bibliography anchor.
The triple brackets around it are preserved.

\((DD AND CC) OR (DD AND EE)) is not interpreted as a flow index term.
The double brackets around it are preserved.

The URL \https://example.org isn't converted into an active link.
查看 示例 88 的结果

在 /items/{id} 中,id 属性不会被替换。它周围的花括号会被保留。

*Stars* 不会显示为粗体文本。它周围的星号会被保留。

&sect; 显示为实体引用。它不会转换为节符号(§)。

=> 反斜杠阻止等号后跟大于号组合成双箭头字符(⇒)。

[[Word]] 不会被解释为锚点。它周围的双括号会被保留。

[[[Word]]] 不会被解释为书目锚点。它周围的三括号会被保留。

((DD AND CC) OR (DD AND EE)) 不会被解释为流程索引词。它周围的双括号会被保留。

URL https://example.org 不会被转换为活动链接。

示例 89. 单双加号行内直通
A word or phrase between single pluses, such as +/user/{id}+,
is not substituted.
However, the special characters like +<+ and +>+ are still
escaped in the output.

An attribute reference within a word, such as dev++{conf}++,
is not replaced.

A plus passthrough will escape standalone formatting marks,
like +``+, or formatting marks within a word, like all-natural++*++.
查看 示例 89 的结果

夹在单加号之间的单词或短语,例如 /user/{id},不会被替换。但是,像 < 和 > 这样的特殊字符仍然会在输出中被转义。

单词内的属性引用,例如 dev{conf},不会被替换。

加号直通会转义独立的格式标记,如 `,或单词内的格式标记,如 all-natural*。

示例 90. 三加号行内直通和行内直通宏
+++<del>strike this</del>+++ is marked as deleted.

pass:[<del>strike this</del>] is also marked as deleted.
查看 示例 90 的结果

删除这个被标记为已删除。

删除这个也标记为已删除。

书目

示例 91. 带入站引用的书目
_The Pragmatic Programmer_ <<pp>> should be required reading for all developers.
To learn all about design patterns, refer to the book by the "`Gang of Four`" <<gof>>.

[bibliography]
== References

* [[[pp]]] Andy Hunt & Dave Thomas. The Pragmatic Programmer:
From Journeyman to Master. Addison-Wesley. 1999.
* [[[gof,gang]]] Erich Gamma, Richard Helm, Ralph Johnson & John Vlissides.
Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley. 1994.
查看 示例 91 的结果

务实的程序员 [pp] 应该是所有开发者的必读书目。要了解设计模式的所有知识,请参考“四人帮”的书 [gang]

参考文献

  • [pp] Andy Hunt & Dave Thomas. The Pragmatic Programmer: From Journeyman to Master. Addison-Wesley. 1999.

  • [gang] Erich Gamma, Richard Helm, Ralph Johnson & John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley. 1994.

脚注

示例 92. 普通和可重用脚注
A statement.footnote:[Clarification about this statement.]

A bold statement!footnote:disclaimer[Opinions are my own.]

Another bold statement.footnote:disclaimer[]
查看 示例 92 的结果

一个陈述。[1]

一个大胆的陈述![2]

另一个大胆的陈述。[2]


1. 关于此陈述的澄清。
2. 观点仅代表个人。

Markdown 兼容性

Markdown 兼容语法是 AsciiDoc 语言的可选功能,目前仅在使用 Asciidoctor 时可用。

示例 93. Markdown 风格的标题
# Document Title (Level 0)

## Section Level 1

### Section Level 2

#### Section Level 3

##### Section Level 4

###### Section Level 5
查看 示例 93 的结果

文档标题(0 级)

1 级节

2 级节

3 级节

4 级节
5 级节
示例 94. 带语法高亮的围栏代码块
```ruby
require 'sinatra'

get '/hi' do
  "Hello World!"
end
```
查看 示例 94 的结果
require 'sinatra'

get '/hi' do
  "Hello World!"
end
示例 95. Markdown 风格的块引用
> I hold it that a little rebellion now and then is a good thing,
> and as necessary in the political world as storms in the physical.
> -- Thomas Jefferson, Papers of Thomas Jefferson: Volume 11
查看 示例 95 的结果

我认为偶尔的小规模叛乱是件好事,在政治世界中与物理世界中的风暴一样有必要。

— 托马斯·杰斐逊
托马斯·杰斐逊论文:第 11 卷
示例 96. 带块内容的 Markdown 风格块引用
> > What's new?
>
> I've got Markdown in my AsciiDoc!
>
> > Like what?
>
> * Blockquotes
> * Headings
> * Fenced code blocks
>
> > Is there more?
>
> Yep. AsciiDoc and Markdown share a lot of common syntax already.
查看 示例 96 的结果

有什么新鲜事?

我的 AsciiDoc 里有 Markdown 了!

什么?

  • 引用块

  • 标题

  • 围栏代码块

还有更多吗?

是的。AsciiDoc 和 Markdown 已经共享了很多常用语法。

示例 97. Markdown 风格的主题分隔符
---

- - -

***

* * *
查看 示例 97 的结果