{"id":137,"date":"2010-04-17T17:21:29","date_gmt":"2010-04-17T16:21:29","guid":{"rendered":"http:\/\/www.naughtynathan.co.uk\/?p=137"},"modified":"2010-04-17T18:10:00","modified_gmt":"2010-04-17T17:10:00","slug":"code-syntax-highlighting-part-ii","status":"publish","type":"post","link":"https:\/\/www.naughtynathan.co.uk\/?p=137","title":{"rendered":"Code Syntax Highlighting &#8211; part II"},"content":{"rendered":"<p>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.<br \/>\nHowever, if I&#8217;d known what utter hell it was going to be I may have reconsidered. It&#8217;s taken me basically the whole day to get this much working and that&#8217;s only due to the help of a WordPress\/PHP savvy mate (cheers John).<\/p>\n<p>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&#8217;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&#8217;t get word-wrapping to turn off either..! so I ditched that and tried SuperHighlighter Evolved. <\/p>\n<p>SuperHighlighter Evolved seemed great but I couldn&#8217;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&#8217;s underlying PHP gobbledegook. Goodbye SuperHighlighter Evolved&#8230;<br \/>\n\u00a0<br \/>\nFinally I plumped for Syntax Highlighter and Code Prettifier (by Vijesh Mehta) which seems to almost work so far.. once I&#8217;ve hacked around with the settings a bit! \ud83d\ude1b<\/p>\n<p>like so:<\/p>\n<p>MEL Script :<\/p>\n<pre class=\"brush:mel; gutter:false; wrap-lines:false\">\r\n\/\/ this proc returns the id number(s) of the scriptjob(s) using the given command (if existing)\r\n\/\/ this can be used not only to simply query the scriptjob Id so you can edit or kill it, but\r\n\/\/ also as a true\/false exists check as it returns false if the scriptjob is not found.\r\nglobal proc int[] getScriptJobID(string $command)\r\n{\r\n\tstring $sjs[] = `scriptJob -lj`;\t\/\/ list ALL jobs\r\n\tint $jobs[] = {};\r\n\tfor ($sj in $sjs)\r\n\t{\t\/\/ loop through each job description looking for our command string\r\n\t\tif (`gmatch $sj (\"*\"+$command+\"*\")`)\r\n\t\t{\r\n\t\t\tstring $token[];\r\n\t\t\ttokenize $sj \":\" $token;\r\n\t\t\t$jobs[size($jobs)] = $token[0];\r\n\t\t}\r\n\t}\r\n\treturn $jobs;\r\n}\r\n<\/pre>\n<p>Python Script:<\/p>\n<pre class=\"brush:python; wrap-lines:false; gutter:false\">\r\ndef typecastString(inputStr):\r\n\t\"\"\"Given an input STRING this returns it cast into the correct type;\r\n\tint, float, or string depending on what it contains.\"\"\"\r\n\r\n\tinputStr = str(inputStr)\t# just in case the input is not a string\r\n\r\n\toutput = inputStr\r\n\r\n\tif inputStr.isdigit():\r\n\t\toutput = int(inputStr)\r\n\telif inputStr.replace('.','',1).isdigit():\r\n\t\toutput = float(inputStr)\r\n\r\n\treturn output\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;d known what utter hell it was going to be I may have reconsidered. It&#8217;s taken me basically the whole day [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,7],"tags":[],"class_list":["post-137","post","type-post","status-publish","format-standard","hentry","category-mel","category-python"],"_links":{"self":[{"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=137"}],"version-history":[{"count":11,"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/137\/revisions"}],"predecessor-version":[{"id":286,"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/137\/revisions\/286"}],"wp:attachment":[{"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.naughtynathan.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}