Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m looking for a way to display code in my (custom, proprietary) blog in a nic

ID: 657653 • Letter: I

Question

I'm looking for a way to display code in my (custom, proprietary) blog in a nice way. So I need some kind of syntax highlighter. BUT WAIT. I'm actually planning on posting several equivalent code snippets in different languages, and ideally I'd like for it to have tabs that someone can quickly flip through to see the different versions. For example, one tab for Java, another tab for PHP, and so on.

I recognize that I could find a syntax highlighting library I like and then wrap it in my own code to switch the tabs, but I'm hoping there's already a library that has this feature out of the box. Any suggestions?

Explanation / Answer

The python library pygments can syntax highlight over 300 languages, (you can define more), and output to a number of formats among them HTML, RTF, LaTeX and ANSI sequences or you can define custom formatters.

It comes with a command line interface pygmentize but there is also a jython port jygments that you could use.

There is also Pygmentize (Bundled) which provides a JavaScript interface to pygments.
Re Tabs:

Since your code samples will be in different languages, hence have different content, in each tab the syntax highlighting does not need to be tab aware you can simply syntax highlight your code samples for each tab and serve them as static web elements.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote