Asciidoctor: How to highlight whole lines with coderay?

Created on 20 Sep 2017  路  4Comments  路  Source: asciidoctor/asciidoctor

My environment: Windows, using AsciidoctorJ and publishing to html, revealjs and pdf.

I am using coderay because it is compatible with AsciidoctorJ.

These instructions show that coderay will highlight line numbers only, not whole lines.

I understand that I can specifiy a parameter to get coderay to highlight the whole line, since the method exists in coderay (see public method "begin_line"): http://coderay.rubychan.de/doc/CodeRay/Encoders/HTML.html

How should I modify the following example.adoc to get lines 1 and 2 of the Arduino code entirely highlighted? Or which config file should I tweak?

= IoT for entrepreneurs: the code explained (part 1)
Cl茅ment Levallois <[email protected]>
2017-09-04

last modified: {docdate}

:icons!:
:iconsfont:   font-awesome

:source-highlighter: coderay
:coderay-linenums-mode: table
:title-logo-image: EMLyon_logo_corp.png[align="center"]

== The code, explained steps by steps
[source,arduino,linenums,highlight='1-2']
----
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <Wire.h>
----

Most helpful comment

This is not something that CodeRay supports and we're not in the business of making syntax highlighters. You can either use asciidoctor-rouge or the integrated support for Rouge coming in Asciidoctor 2.0. For all intents and purposes, CodeRay integration is now deprecated.

All 4 comments

The first thing I noticed is that you're document attributes are violating this rule:

http://asciidoctor.org/docs/user-manual/#doc-header

But the problem is deeper than that.

CodeRay does not support custom highlighting / spotlighting of whole lines. Instead, it only emboldens the line number. This is one of the main reasons I don't like CodeRay and I have proposed to replace it with Rouge (#1040).

The begin_line function mentioned in the CodeRay API is for highlighting lines in source languages that require whole line highlighting, such as in diffs. This is not in any way related to the custom highlighting / spotlighting.

So the highlights specified in your source block are being honored...it's just that CodeRay doesn't behave in the way we expect it to. And there doesn't seem to be any way around in.

Personally, I'm not making any more investment in CodeRay. I think it's a waste of time. If I spend any time at all in this part of the code, it will be to rip out CodeRay and replace it with Rouge. And that's on my list for 1.5.7.

You can now use Rouge instead of CodeRay: asciidoctor-rouge, lines highlighting is supported.

This is not something that CodeRay supports and we're not in the business of making syntax highlighters. You can either use asciidoctor-rouge or the integrated support for Rouge coming in Asciidoctor 2.0. For all intents and purposes, CodeRay integration is now deprecated.

Was this page helpful?
0 / 5 - 0 ratings