Changing code size in syntax highlighted code block

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing code size in syntax highlighted code block

daveb
I am using coderay to highlight code but one of the changes between 1.4 and 1.5 was to increase the font size (maybe just as a consequence of using different fonts?).  I would like to reduce the size of the font, but am at a loss how to do this either at the asciidoc level or through coderay (as I am invoking it via an extension).

Thanks,

Dave.
Reply | Threaded
Open this post in threaded view
|

Re: Changing code size in syntax highlighted code block

mojavelinux
Administrator
The quickest way is to the use a docinfo file {1}. You can put any styles you want in that file. It gets included in the <head> tag of the HTML.

The shortcoming of CodeRay at the moment is that it doesn't have alternate themes out of the box (and we don't currently load a custom theme for it). Once we do, then you could just specify an attribute like `coderay-style` and provide your own theme.

-Dan

p.s. FYI, why we made the font larger. The larger font size is kinder to your readers. Plus, the font size shrinks as the screen size gets smaller.



On Thu, Aug 21, 2014 at 10:07 AM, daveb [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I am using coderay to highlight code but one of the changes between 1.4 and 1.5 was to increase the font size (maybe just as a consequence of using different fonts?).  I would like to reduce the size of the font, but am at a loss how to do this either at the asciidoc level or through coderay (as I am invoking it via an extension).

Thanks,

Dave.



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Changing-code-size-in-syntax-highlighted-code-block-tp2040.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Changing code size in syntax highlighted code block

daveb
Thanks, Dan.

I was already running a post processor extension to add extra content into the TOC (hyperlinks into the functions defined in the listings), so I just added another postprocessor:

Extensions.register {postprocessor ReduceListingFontSizePostprocessor}

# Reduce the font size for code listings as this was increased in 1.5
class ReduceListingFontSizePostprocessor < Asciidoctor::Extensions::Postprocessor
        def process(document, output)
                output.sub(/code,kbd,pre,samp{font-family:monospace;font-size:1em}/,
                          "code,kbd,pre,samp{font-family:monospace;font-size:0.92em}")
        end
end


Maybe not the most elegant or robust way of doing the job, but it works and has the advantage of not having to put docinfo files in the dozens of directories where these documents are held.

Dave.
Reply | Threaded
Open this post in threaded view
|

Re: Changing code size in syntax highlighted code block

mojavelinux
Administrator

On Fri, Aug 22, 2014 at 3:33 AM, daveb [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Maybe not the most elegant or robust way of doing the job, but it works and has the advantage of not having to put docinfo files in the dozens of directories where these documents are held.

Elegant is when it works for you, not how it works :)

I do strongly recommend that you consider using a custom stylesheet if you make further customizations. You can either hack on the original (which is minified) or you can go back and build one using the Asciidoctor stylesheet factory:


Cheers,

-Dan

--