Asciidoctor-pdf style overwrite possible?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Asciidoctor-pdf style overwrite possible?

Claudius Heine
Hi,

I am currently writing a presentation with asciidoctor-revealjs and
also like to generate a handout from this using asciidoctor-pdf.

I have some bash code passages that need to be executed in different
contexts, so I choose to add classes to those code passages like this:

  [.greencode, source, bash]
  ----
  include::source.sh[tag=some-tag]
  ----

And then use the customcss attribute to change the background color of
this code segment like this:

  .greencode code {
      background-color: darkgreen;
  }

And that works great!

But how can I do something similar in the pdf output?

If I understand the documentation about the pdf styling correctly, then
its only possible to change the background of all code passages and not
just selectively. Is there a way around this or did I overlooked
something?

Thanks!
Claudius

--
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-54 Fax: (+49)-8142-66989-80 Email: [hidden email]

            PGP key: 6FF2 E59F 00C6 BC28 31D8 64C1 1173 CB19 9808 B153
                              Keyserver: hkp://pool.sks-keyservers.net

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor-pdf style overwrite possible?

mojavelinux
Administrator
Asciidoctor PDF was not designed for this level of customization. However, it's possible to monkeypatch the converter to alter the behavior. I'll explain how to do that.

First, create a patched version of the converter in the file mypdfconverter.rb:

require 'asciidoctor-pdf'
 
module MyPdfConverter
  def convert_listing node
    code_background_color = @theme.code_background_color
    @theme.code_background_color = '00ff00' if node.has_role? 'green'
    super
    @theme.code_background_color = code_background_color
  end
end

class Asciidoctor::Pdf::Converter
  prepend MyPdfConverter
end

Next, load this file when invoking asciidoctor-pdf:

asciidoctor-pdf -r ./mypdfconverter.rb document.adoc

You should see that the listing block with the role "green" now has a green background.

Note, the prepend command creates a hierarchy similar to extending the class, except creates the hierarchy in place.

Cheers,

-Dan

On Wed, Aug 1, 2018 at 4:44 AM Claudius Heine [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi,

I am currently writing a presentation with asciidoctor-revealjs and
also like to generate a handout from this using asciidoctor-pdf.

I have some bash code passages that need to be executed in different
contexts, so I choose to add classes to those code passages like this:

  [.greencode, source, bash]
  ----
  include::source.sh[tag=some-tag]
  ----

And then use the customcss attribute to change the background color of
this code segment like this:

  .greencode code {
      background-color: darkgreen;
  }

And that works great!

But how can I do something similar in the pdf output?

If I understand the documentation about the pdf styling correctly, then
its only possible to change the background of all code passages and not
just selectively. Is there a way around this or did I overlooked
something?

Thanks!
Claudius

--
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-54 Fax: (+49)-8142-66989-80 Email: [hidden email]

            PGP key: 6FF2 E59F 00C6 BC28 31D8 64C1 1173 CB19 9808 B153
                              Keyserver: hkp://pool.sks-keyservers.net

signature.asc (849 bytes) Download Attachment



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-pdf-style-overwrite-possible-tp6439.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux