Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Add dedicated section or page for the linenums option on source blocks #77

Closed
mojavelinux opened this issue Aug 5, 2021 · 1 comment

Comments

@mojavelinux
Copy link
Member

Source blocks support the linenums option. This option adds line numbers to the rendered source block when supported by the source highlighter or converter.

:source-highlighter: rouge

[source%linenums,js]
----
function fib (n) {
  if (n < 2) return n
  return fib(n - 1) + fib(n - 2)
}

console.log([1, 2, 3, 4, 5].map(fib))
----

The linenums option can also be specified as the third positional (unnamed) attribute on the source block.

:source-highlighter: rouge

[source,js,linenums]
----
function fib (n) {
  if (n < 2) return n
  return fib(n - 1) + fib(n - 2)
}

console.log([1, 2, 3, 4, 5].map(fib))
----

However, the named option is preferred. The option can also be enabled globally by setting the source-linenums-option attribute.

The docs should emphasize that while the option is a part of the AsciiDoc language, it does require support from the toolchain (syntax highlighter adapter, converter, and/or output format), so it may not always be honored.

The linenums option is documented in passing in the Asciidoctor docs on the page for each syntax highlighter adapter. See:

However, this topic deserves its own section or page to define it and solidify it as part of the AsciiDoc language.

@graphitefriction
Copy link
Member

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants