Highlight some part of a source code (pygments)

540 views
Skip to first unread message

Ramzi Akremi

unread,
Oct 30, 2011, 5:31:40 PM10/30/11
to asciidoc
Hi all,

I would like to emphasize some part of a source when using asciidoc

for instance, I have this portion of text

[source, ruby, numbered]
------------
total_amount, frequent_renter_points = 0, 0
result = "Rental Record for #{name}\n"
@rentals.each do |element|
this_amount = 0
-------------

I would like to make lines 2 to 4 appear differently (another
background or in bold), how can I pass these kind of parameters to the
pigments highlighter

I've followed the hl_lines trail which works well in command line but
I would like to streamline this with my asciidoc workflow.

thanks in advance

Lex Trotman

unread,
Oct 30, 2011, 6:03:06 PM10/30/11
to asci...@googlegroups.com
On 31 October 2011 08:31, Ramzi Akremi <ramzi....@gmail.com> wrote:
> Hi all,
>
> I would like to emphasize some part of a source when using asciidoc
>
> for instance, I have this portion of text
>
> [source, ruby, numbered]
> ------------
>  total_amount, frequent_renter_points = 0, 0
>  result = "Rental Record for #{name}\n"
>  @rentals.each do |element|
>    this_amount = 0
> -------------
>
> I would like to make lines 2 to 4 appear differently (another
> background or in bold), how can I pass these kind of parameters to the
> pigments highlighter

There is no built-in for extra parameters for pygmentize, you will
have to make a custom conf file containing:

source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered"),filter="pygmentize
-f html -l {language} {src_numbered?-O linenos=table} {encoding?-O
encoding={encoding}}"

with attributes for the extra parameters added.

Cheers
Lex

>
> I've followed the hl_lines trail which works well in command line but
> I would like to streamline this with my asciidoc workflow.
>
> thanks in advance
>

> --
> You received this message because you are subscribed to the Google Groups "asciidoc" group.
> To post to this group, send email to asci...@googlegroups.com.
> To unsubscribe from this group, send email to asciidoc+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/asciidoc?hl=en.
>
>

Ramzi Akremi

unread,
Oct 31, 2011, 11:46:04 AM10/31/11
to asciidoc
Thanks a lot Lex

I had to read a little bit about asciidoc configuration files, but it
worked
Here is the configuration setting that I've added to source-highlight-
filter.conf

ifdef::pygments[source-style=template="source-highlight-
block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered","src_emphasize"),filter="pygmentize
-f html -l {language} {src_numbered?-O linenos=table} {encoding?-O
encoding={encoding}} {src_emphasize?-O \"hl_lines={src_emphasize}\"}"]

Worked really well, so now in an asciidoc file I can declare this :

[source, ruby, numbered, 1 10 13]
-------
the source code
-------

Thanks again

On Oct 30, 11:03 pm, Lex Trotman <ele...@gmail.com> wrote:
> On 31 October 2011 08:31, Ramzi Akremi <ramzi.akr...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > Hi all,
>
> > I would like to emphasize some part of a source when using asciidoc
>
> > for instance, I have this portion of text
>
> > [source, ruby, numbered]
> > ------------
> >  total_amount, frequent_renter_points = 0, 0
> >  result = "Rental Record for #{name}\n"
> >  @rentals.each do |element|
> >    this_amount = 0
> > -------------
>
> > I would like to make lines 2 to 4 appear differently (another
> > background or in bold), how can I pass these kind of parameters to the
> > pigments highlighter
>
> There is no built-in for extra parameters for pygmentize, you will
> have to make a custom conf file containing:
>
> source-style=template="source-highlight-block",presubs=(),postsubs=("callou ts",),posattrs=("style","language","src_numbered"),filter="pygmentize

Stuart Rackham

unread,
Nov 7, 2011, 12:18:05 AM11/7/11
to asci...@googlegroups.com
I've just committed a patch that adds and 'args' block attribute to source
highlight blocks to allow arbitrary parameters to be passed to the source
highlighters, so your example can now be done out of the box with:

["source","ruby","numbered",args="-O \"hl_lines=1 10 13\""]


-------
the source code
-------

See:
http://code.google.com/p/asciidoc/source/detail?r=64df5f6321971483a2d67c503fb8cd25db59bc11

Cheers, Stuart

Reply all
Reply to author
Forward
0 new messages