Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Awesome Asciidoctor: CSV and DSV Tables

DZone's Guide to

Awesome Asciidoctor: CSV and DSV Tables

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

With Asciidoctor we can create tables where the header and rows are in CSV (Comma Separated Values) and DSV (Delimiter Separated Values) format. Normally we use a pipe-symbol (|) to separate cell values. This is actually PSV (Prefix Separated Values) :-).

In the following Asciidoctor markup we create a very simple table with a header and two rows using CSV:

= Tables

== CSV table

[format="csv", options="header"]
|===
Writing tools, Awesomeness
Asciidoctor, Oh yeah!
MS Word, No!
|===

We generate this into HTML and we get the following result:



Asciidoctor provides also another way to define the above table:

= Tables

==CSV table
// Define table using CSV syntax.
// The start and end of the table is defined
// as ,=== instead of |===.
// Also the header row is followed by new line,
// to indicate it is the header row.

,===
Writing tools, Awesomeness

Asciidoctor, Oh yeah!
MS Word, No!
,===

// We can also specify a separator.

[format="csv", separatory=";", options="header"]
| ===
Name;Description
Asciidoctor;Awesome way to write documentation
| ===

The previous samples used a comma to separate values, but we can also use colon (:). The next sample contains tables defined with DSV:

== DSV table

[format="dsv", options="header"]
|===
Writing tools:Awesomeness
Asciidoctor:Oh yeah!
MS Word:No!
|===

\\ Alternative syntax:

:===
Writing tools: Awesomeness

Asciidoctor: Oh yeah!
MS Word: No!
:===

With the include directive we can also include data from an external CSV of DSV file to create a table (of course also the traditional pipe-symbol separated format can be in an external file)

= Table with external data

format="csv", options="header"]
|===
include::tools.csv[]
|===

The file tools.cv has the following contents:

Writing tools, Awesomeness
Asciidoctor, Oh yeah!
MS Word, No!

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}