Login  Register

Re: Interpret links (or other AsciiDoc syntax) only in specific lines of a [source] block

Posted by mojavelinux on Feb 16, 2021; 9:29am
URL: https://discuss.asciidoctor.org/Interpret-links-or-other-AsciiDoc-syntax-only-in-specific-lines-of-a-source-block-tp8499p8504.html

> it's about how to tell the source highlighter to ignore specific lines (e.g. consider them comment lines) so that Asciidoctor can take over and format the line as a link.

What you're probably looking for is a custom syntax highlighter adapter, which is also an extension point. It is invoked by the converter when it needs to apply syntax highlighting to a source block. This seems to be the perfect opportunity to do the processing you want to do.

Here's an example: https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/syntax_highlighter/rouge.rb

If you want to reuse a built-in adapter, you can extend it by looking it up, and extending the resolved class.

class MyRouge < (Asciidoctor::SyntaxHighlighter.for 'rouge')
  register_for 'rouge'

  # override any methods here
end

-Dan

--
Dan Allen (he, him, his) | @mojavelinux | https://twitter.com/mojavelinux