asciidoctor / asciidoctor.org

:globe_with_meridians: Asciidoctor project site. Composed in AsciiDoc. Baked with Awestruct.
https://asciidoctor.org
Other
323 stars 805 forks source link

What's the difference between "source" and "listing"? #839

Closed john-cj closed 5 years ago

john-cj commented 5 years ago

I have carefully read the docs, but haven't found any explanation about the difference between [source] and [listing]. Here is the Asciidoctor markup and corresponding HTML:

[source]
----
Code source
----

[listing]
----
Code listing
----
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>Code source</code></pre>
</div>
</div>

<div class="listingblock">
<div class="content">
<pre>Code listing</pre>     <-- .highlight class and <code> element disappeared
</div>
</div>

So, from what I see I could say that [listing] is reserved for monospaced computer-related text, like pseudo-tables. Not sure, though. Is it correct assumption?

[listing]
----
|         |        Bar        |
|   Foo   |-------------------|
|         |   Xxx   |   Yyy   |
|-----------------------------|
| ...     | ...     | ...     |
| ...     | ...     | ...     |
| ...     | ...     | ...     |
| ...     | ...     | ...     |
| ...     | ...     | ...     |
----
mojavelinux commented 5 years ago

The source block provides syntax highlighting (when a language is specified). The listing block does not.

john-cj commented 5 years ago

But what's the reason to have [listing] whereas language-less [source] can accomplish the same task, without any downsides?

mojavelinux commented 5 years ago

If the listing style is used on the listing block, it's redundant. But it can also be used on the literal block (to provide an alternate boundary syntax if the content happens to contain a line with 4 hyphens).

Langues-less source should never be used unless you have defined a global language (using the source-language attribute, which is the use case for that syntax).

john-cj commented 5 years ago

Understood, thanks.