AsciiDoc source code block shorthand
In AsciiDoc, you normally make a source code block by adding the source
style and a language to a listing (or literal) block.
[source, ruby]
----
puts "Hello, World!"
[1, [2, 3], 4].flatten.size == 4
----
You need at least four hyphens (e.g., ----
) around the content to create a listing block. But it's possible to get away with less by using an open block!
An open block is a special block that can masquerade as most other delimited blocks. It's created by fencing the content with lines that consist of exactly two hyphens (e.g., --
).
In order to turn an open block into another block, you need to specify the block style (e.g., source
) in the attribute list above the block. Since we're doing that already to create our source code block, it means we can save a total of four hyphen characters (two on either side of the block).
[source, ruby]
--
puts "Hello, World!"
[1, [2, 3], 4].flatten.size == 4
--
Why would you ever type four hyphens around the content to create a source code block in AsciiDoc when you can just as well use two? Less is more :)