Code Syntax Highlighting – part II

Seeing as how this is supposed to be (partially at least) a MEL and Python code blog I thought it only proper that I set up some kind of code syntax highlighting.
However, if I’d known what utter hell it was going to be I may have reconsidered. It’s taken me basically the whole day to get this much working and that’s only due to the help of a WordPress/PHP savvy mate (cheers John).

The first thing I tried was Code-Snippet, which seems pretty good and allowed me to easily write and impliment a new MEL syntax file. But I couldn’t get the colours to change from the defaults, it used the wrong kind of quotes (not good for MEL/py code!) and I couldn’t get word-wrapping to turn off either..! so I ditched that and tried SuperHighlighter Evolved.

SuperHighlighter Evolved seemed great but I couldn’t make that work like the site said it would either. Additionally, creating a new colour theme or Syntax file required a degree in scripting this kind of crap as well as a full understanding of WordPress’s underlying PHP gobbledegook. Goodbye SuperHighlighter Evolved…
Finally I plumped for Syntax Highlighter and Code Prettifier (by Vijesh Mehta) which seems to almost work so far.. once I’ve hacked around with the settings a bit! 😛

like so:

MEL Script :

// this proc returns the id number(s) of the scriptjob(s) using the given command (if existing)
// this can be used not only to simply query the scriptjob Id so you can edit or kill it, but
// also as a true/false exists check as it returns false if the scriptjob is not found.
global proc int[] getScriptJobID(string $command)
	string $sjs[] = `scriptJob -lj`;	// list ALL jobs
	int $jobs[] = {};
	for ($sj in $sjs)
	{	// loop through each job description looking for our command string
		if (`gmatch $sj ("*"+$command+"*")`)
			string $token[];
			tokenize $sj ":" $token;
			$jobs[size($jobs)] = $token[0];
	return $jobs;

Python Script:

def typecastString(inputStr):
	"""Given an input STRING this returns it cast into the correct type;
	int, float, or string depending on what it contains."""

	inputStr = str(inputStr)	# just in case the input is not a string

	output = inputStr

	if inputStr.isdigit():
		output = int(inputStr)
	elif inputStr.replace('.','',1).isdigit():
		output = float(inputStr)

	return output

4 Responses to “Code Syntax Highlighting – part II”

  1. eRiC Says:

    yay! looking good :]
    can I … “borrow” this for my wp-blog?

  2. Naughty Says:

    sure thing Eric, gimme a buzz when you’re next online and I’ll send you over the full details. I’ll put the MEL brush syntax file up here too when it’s finished.

  3. Maulik Says:

    I have created Mel brush for dp syntax highlighter. I posted it some time back on CGTalk programming section. I had changed few things to highlight the command flags as well.

  4. Naughty Says:

    that’s great Maulik, I’ll definitely check that out, many thanks.

Leave a Reply