Loading...

June 11, 2014

Awesome Asciidoctor: Do Not Wrap Lines in Listing or Literal Blocks

When we use listing or literal blocks in our Asciidoc markup long lines will be wrapped if needed in the generated output. We can use the options attribute with a nowrap value to have horizontal scrolling instead of wrapped lines. This applies for the HTML backend when we generate the documentation.

In the following markup we first use the default wrapping of lines:

[source,groovy]
----
class GroovyHelloWorld {
 def sayHello(final String message = 'world') { // Set default argument value for message argument
  "Hello $message !"
 }
}
----

If we generate HTML we get the following output:

If we set the options attribute with the value nowrap the long lines are no longer wrapped and we get a horizontal scrollbar to see the complete code listing:

[source,groovy,options="nowrap"]
----
class GroovyHelloWorld {
 def sayHello(final String message = 'world') { // Set default argument value for message argument
  "Hello $message !"
 }
}
----

The following screenshot shows a horizontal scrollbar when we want to see the rest of the line:

Written with Asciidoctor 0.1.4.