Syntax highlighter for VB/VBA?

Hi guys,
I want to highlight code in Visual Basic for Applications. However, VBA does not seem to be included as a supported language in the documentation. Can i still use highlighter for this? Here is my config.toml:

pygmentsCodeFencesGuessSyntax = true
PygmentsStyle = "perldoc"

I successfully included php highlighted code in one of my articles using:

{{< highlight php >}}
{{< /highlight >}}

Now I want to do the same with VBA. Is there a way to accomplish this?

Probably the closest you can get is VB - is that in the list?

While nowhere near the same tool, VBA is syntactically similar to older versions of VB. Not many tools support VBA highlighting as it is rarely used outside specific applications such as Microsoft Office.

Unfortunately (and surprisingly to me), VB is also not in the list

The only other thing I can suggest is that you use a highlighting editor that lets you copy as HTML. Then past that directly rather than using the highlighter.

Chroma indeed doesn’t seem to have a VB (.NET) highlight. Not that I can see in the Chroma repository at least. You could open an issue here to request for its inclusion.

A quicker way is to use a JavaScript plugin like Prism in your theme. They support Visual Basic and Prism is lightweight, so only a small performance hit. I also use Prism for languages that Hugo (Chroma) doesn’t recognise.

There are also plenty of other JavaScript-based code highlighters, of course.

Not good for a static site really though, no matter how lightweight.

Really depends on how many posts containing VBA will be created and over what frequency.

That’s a pretty black/white statement. 6kb of JavaScript to get syntax highlight is a much better deal than no syntax highlight, in my view.

I’m not sure where you get the idea that JavaScript is no good for a static site. Yes it’s not ideal, but totally throwing away syntax highlighting because it’s not ideal seems a bit strange.

Nah this is irrelevant I think. If you wrap the VBA highlight in a shortcode, you can use .HasShortcode to only load the JavaScript for the pages that actually need it.

That way it doesn’t matter if 2% of posts or 90% of posts needs syntax highlight; it then only gets loaded in 100% of the cases when it’s actually needed. So that would be my tip for Badan. :slight_smile:

I was actually meaning the other way around. If you aren’t doing many, then copying from another editor and pasting as html isn’t a large overhead. If, on the other hand, you are doing loads then clearly you will want something such as your suggestion.

@TotallyInformation, thank you very much for the help! I never thought I can do something so simple as using online highlighting editor that generates html code but this is exactly what I need! Now my post looks way better!

Thanks everyone for your support!

1 Like