code highlighting

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

code highlighting

dan34
Hi, I've been using asciidoc for a long time, but new to asciidoctor.

I'm having trouble geting code highlighting to work in AD. The code is a shell script.  I tried pygments and highlight.js but they don't seem to have any effect while coderay turns all the code red.

I'm probably overlooking something simple, but I don't know what.


Reply | Threaded
Open this post in threaded view
|

Re: code highlighting

abelsromero
Welcome :)

I asume you're trying to highlight bash, right? If that's the case, I have run a couple of tests and I could get it working with 'prettify' and 'highlightjs'. According to coderay's site bash is not supported and pygments is not working for me due to some problems with the ruby gem when using it from Java with asciidoctorj.

If you're using directly the ruby command I think that you need to install and set the additional gems to do the highlighting. If you are not a Ruby person (like myself :P), I can recommend you to use gvm with Asciidoctorj to ease the use of shell renderings and gem managing (http://gvmtool.net/).

Finally, here's an example of the block I used:

[source,bash]
----
#!/bin/bash
HELLO=Hello
function hello {
    local HELLO=World
    echo $HELLO
}
echo $HELLO
hello
echo $HELLO          
----
Please, let us know if this helps.
Reply | Threaded
Open this post in threaded view
|

Re: code highlighting

dan34
Thanks for the help. I was able to get it working. One of the things that was contributing to the problem was that a Firefox plugin was blocking the rendering of the code. I finally tried the chromium browser and it worked. Then going back to firefox I disabled the request policy plugin and it worked. Straight asciidoc does something different so it's not blocked by that filter. Anyway, it works now.
Reply | Threaded
Open this post in threaded view
|

Re: code highlighting

abelsromero
Glad to hear that :)
If you need to, most of external resources like images and css can be embedded to create self-contained HTML files. I'm not a fan but can be usefull sometimes.
Just lokk for "linkcss" and "Embedded" info here (http://asciidoctor.org/docs/asciidoc-syntax-quick-reference/) and here (http://asciidoctor.org/docs/render-documents/)

Finally, as a personal request to fully understand the case and see if there’s anything to improve, can you explain how are you generating the output? Shell command, Gradle, Maven, other?

Thanks,