Stan support in highlight.js

78 views
Skip to first unread message

Brendan

unread,
Dec 11, 2015, 2:07:07 PM12/11/15
to Stan users mailing list
Dear List,

Some Friday fluff for you. 

Inspired by the wonderful support in Rstudio, I recently had a quick go at syntax highlighting for Stan via highlight.js (commonly used for highlighting code in HTML form).

It was a quick lunch-break hack, but it's an improvement on unformatted text, I hope!

I've submitted it as a pull request to the highlight.js maintainers (it looks like it's being considered for the 9.1 release). 

If anyone would like to change/improve it, I'd be very happy to accept a pull request and propagate the changes into the highlight.js PR.

Thanks again for Stan!

Best,

Brendan

Bob Carpenter

unread,
Dec 11, 2015, 6:39:09 PM12/11/15
to stan-...@googlegroups.com
Thanks. Let us know how it goes. I don't know
anything about the project.

Where does that highlighting get used?
Rstudio editor? knitr? Any way I could plug it
into our Jekyll-based web site?

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Brendan

unread,
Dec 11, 2015, 11:19:41 PM12/11/15
to Stan users mailing list
It's great for Jekyll sites (I use it on mine), mainly because it all works client-side -- you just link to the js and css in a template/layout file. No need to use funny markup, or reprocess HTML as a build step.

It supports other languages likely to be used on the same site (R, Python, C++, Matlab, Stata, etc.).

I imagine it could be used with knitr/Rmarkdown (with a user-specified HTML template file). Rstudio already has fantastic Stan support thanks to Jeffery Arnold.

In fact, as I'm writing this, I've just checked out his GitHub, and noticed that he's already written Stan HTML highlighters for Pygments and Prettify, as well as highlighters for LaTex, and Emacs!

So, JA is definitely the person to ask. If you guys would like to eyeball a couple of options, I'd be happy to submit a highlight.js example PR.

Brendan

Bob Carpenter

unread,
Feb 16, 2016, 4:28:23 PM2/16/16
to stan-...@googlegroups.com
I'm about to start putting knitr docs up on our web
site. Does anyone know how to deal with any of these
issues and want to help out? As is, my Stan code just
renders as black text.

- Bob

Jonah Gabry

unread,
Feb 16, 2016, 8:54:28 PM2/16/16
to Stan users mailing list
Jeff Arnold might be your guy

Jeffrey Arnold

unread,
Feb 16, 2016, 9:42:34 PM2/16/16
to Stan users mailing list
Awesome! Having highlight.js is great for the reasons Brandan already mentioned: it is client-side, so you only need to include the javascript for it to get highlighting. Highlight.js is also the default highlighter than rmarkdown uses. How can I help?

On Tue, Feb 16, 2016 at 5:54 PM, Jonah Gabry <jga...@gmail.com> wrote:
Jeff Arnold might be your guy

Bob Carpenter

unread,
Feb 16, 2016, 9:57:27 PM2/16/16
to stan-...@googlegroups.com
Is there a version for Stan and if so, how do I turn
on highlighting for knitr docs? I'm going to be pulling
in the Stan programs from external files, not including
them as part of the .Rmd directly.

- Bob

Jeffrey Arnold

unread,
Feb 17, 2016, 1:08:24 AM2/17/16
to Stan users mailing list
knitr on its own will convert Rmd files to md files. For highlight.js to work will depend on whether the markdown converter wraps code in <pre><code>. See https://highlightjs.org/usage/ for using highlight.js, and babelmark for a comparison of how markdown converters would handle code blocks. 

Which repo are you doing this in? 
Reply all
Reply to author
Forward
0 new messages