Quantcast

Unable to show syntax highlighting through Pygments

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unable to show syntax highlighting through Pygments

cricrazy
I stumbled upon AsciiDoctor from one of the youtube videos by Dan Allen. I have been looking for a better way to write technical documentation. AsciiDoctor is an incredible tool. In the past I had tried Markdown, but gave up on it, due to limited options. I have been using AsciiDoctor ever since for many documents. Recently, I came across an issue with the syntax highlighting.  (there was a similar issue reported back in 2013 (Issue), I don't know if these are related.

Whenever I use pygments theme like Monokai or Jellybeans. It has some issues with background color. It is not with all source files, C works fine, but IDL does not work. Can you please help? (I am also attaching the asciidoc text).



:source-highlighter: pygments
:pygments-style: monokai
:pygments-css: class

[source,c]
----
static void Redisplay(Widget w, XEvent *event, Region region)
{
  for (i=0; i<array->composite.num_children; i++) {
    RectObj	child = (RectObj)array->composite.children[i];
    RectObjClass	roclass;
    if (!XtIsManaged((Widget)child) || XtIsWidget(child))
      continue;
    if (region)
      if (!XRectInRegion(region, child->rectangle.x, child->rectangle.y,
			 child->rectangle.width, child->rectangle.height))
	continue;

    roclass = (RectObjClass)child->object.widget_class;

    if (roclass->rect_class.expose)
      roclass->rect_class.expose((Widget)child, event, region);
  }
}
----

[source, IDL]
----
a = {,a:0.}
b = {,b:''}
c = [a, b]

FOR i = upc1, upc2 DO BEGIN <1>
    data_cols = data_cols + ",d" +STRING_COMP (i+1) + ":0."
    tokens = STRPARSE (upc(i), DELIM = !NL)
    columns1 = [columns1, tokens(0)] 
    columns2 = [columns2, props(tokens(1) - 1).property]
    columns3 = [columns3, tokens(1)]
    formats = [formats, dformat]
ENDFOR
----
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to show syntax highlighting through Pygments

mojavelinux
Administrator
A style from the default Asciidoctor stylesheet is overriding the general text color specified by the Pygments theme. Unfortunately, this is extremely tricky to get right because we have so many permutations we're trying to cover.

As a workaround, you can fix it by adding the following to a docinfo file:

<style>
.listingblock .pygments code { color: #f8f8f2 }
</style>

Right now, the style on code (and pre>code) from the default stylesheet is winning out.

To fix this, we'll need to strengthen the CSS rule that specifies the general color. I have submitted a pull request that implements this solution.


-Dan

On Thu, Jun 23, 2016 at 1:35 PM, cricrazy [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I stumbled upon AsciiDoctor from one of the youtube videos by Dan Allen. I have been looking for a better way to write technical documentation. AsciiDoctor is an incredible tool. In the past I had tried Markdown, but gave up on it, due to limited options. I have been using AsciiDoctor ever since for many documents. Recently, I came across an issue with the syntax highlighting.  (there was a similar issue reported back in 2013 (Issue), I don't know if these are related.

Whenever I use pygments theme like Monokai or Jellybeans. It has some issues with background color. It is not with all source files, C works fine, but IDL does not work. Can you please help? (I am also attaching the asciidoc text).



:source-highlighter: pygments
:pygments-style: monokai
:pygments-css: class

[source,c]
----
static void Redisplay(Widget w, XEvent *event, Region region)
{
  for (i=0; i<array->composite.num_children; i++) {
    RectObj	child = (RectObj)array->composite.children[i];
    RectObjClass	roclass;
    if (!XtIsManaged((Widget)child) || XtIsWidget(child))
      continue;
    if (region)
      if (!XRectInRegion(region, child->rectangle.x, child->rectangle.y,
			 child->rectangle.width, child->rectangle.height))
	continue;

    roclass = (RectObjClass)child->object.widget_class;

    if (roclass->rect_class.expose)
      roclass->rect_class.expose((Widget)child, event, region);
  }
}
----

[source, IDL]
----
a = {,a:0.}
b = {,b:''}
c = [a, b]

FOR i = upc1, upc2 DO BEGIN <1>
    data_cols = data_cols + ",d" +STRING_COMP (i+1) + ":0."
    tokens = STRPARSE (upc(i), DELIM = !NL)
    columns1 = [columns1, tokens(0)] 
    columns2 = [columns2, props(tokens(1) - 1).property]
    columns3 = [columns3, tokens(1)]
    formats = [formats, dformat]
ENDFOR
----



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Unable-to-show-syntax-highlighting-through-Pygments-tp4794.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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to show syntax highlighting through Pygments

cricrazy
Dan,

Thanks a lot. I tried the work around. I created a docinfo.html file in the current working directory. And added
:docinfo1: attribute
 in the asciidoc file. It works great. Here is the output.



Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to show syntax highlighting through Pygments

mojavelinux
Administrator
Glad to hear it!


:docinfo1: attribute

If you are using Asciidoctor 1.5.4, it's better to use the new attribute:

:docinfo: shared 

That loads docinfo.html. (The other option is private, which loads the docinfo specific to the current file).

-Dan

--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to show syntax highlighting through Pygments

cricrazy
Thanks Dan. I will try these attributes too.
Loading...