Archive for the ‘Open Source Software’ Category

Updated WordPress Code Highlighter to GeSHi 1.0.8.6

Wednesday, May 12th, 2010

Today I've been tracking down a little rendering bug with MarsEdit and WordPress. It's in the pre tags that run through the Code Highlighter plugin that I've been using for quite a while. It's the "less-than-sign". If I use the HTML escape code then I get that as the literal text in the MarsEdit preview pane as well as the WordPress page. But if I place the single character, MarsEdit thinks it's the start of a tag, and gets confused on the syntax highlighting.

So the two questions are: why can't the Code Highlighter handle the HTML escape for the less-than-sign, and why is MarsEdit not rendering it properly? I'm going to attack the first, and let Daniel handle the second.

First thing I noticed was that the Code Highlighter is based on the GeSHi engine and the version it's working on was 1.0.7.x whereas the current version is 1.0.8.6. So let's see if we can update the GeSHi engine in the plugin without breaking anything.

Turns out, it's a pretty simple encapsulation of the GeSHi engine. I was able to drop in the new version without too much trouble. In the doing, I've upgraded the languages that this guy can work with considerably. That's a very nice little perk.

Unfortunately, this didn't solve the problem with the less-than-sign. I did a cursory look in the GeSHi code and didn't see where it'd be doing any conversions. I'll probably spend a little more time on it - just to see if it's possible. But even if that doesn't come to anything, we have a far better selection of supported languages:

4cs            div            lscript       python
abap           dos            lsl2          qbasic
actionscript   dot            lua           rails
actionscript3  eiffel         m68k          rebol
ada            email          make          reg
apache         erlang         mapbasic      robots
applescript    fo             matlab        rsplus
apt_sources    fortran        mirc          ruby
asm            freebasic      mmix          sas
asp            fsharp         modula3       scala
autohotkey     gambas         mpasm         scheme
autoit         gdb            mxml          scilab
avisynth       genero         mysql         sdlbasic
awk            gettext        newlisp       smalltalk
bash           glsl           nsis          smarty
basic4gl       gml            oberon2       sql
bf             gnuplot        objc          systemverilog
bibtex         groovy         ocaml-brief   tcl
blitzbasic     haskell        ocaml         teraterm
bnf            hq9plus        oobas         text
boo            html4strict    oracle11      thinbasic
c              idl            oracle8       tsql
c_mac          ini            pascal        typoscript
caddcl         inno           per           vb
cadlisp        intercal       perl          vbnet
cfdg           io             perl6         verilog
cfm            java           php-brief     vhdl
cil            java5          php           vim
clojure        javascript     pic16         visualfoxpro
cmake          jquery         pike          visualprolog
cobol          kixtart        pixelbender   whitespace
cpp-qt         klonec         plsql         whois
cpp            klonecpp       povray        winbatch
csharp         latex          powerbuilder  xml
css            lisp           powershell    xorg_conf
cuesheet       locobasic      progress      xpp
d              logtalk        prolog        z80
dcs            lolcode        properties
delphi         lotusformulas  providex
diff           lotusscript    purebasic

[5/13] UPDATE: I was doing some more digging into the GeSHi engine - actually the Code Highlighter plugin, and I found what I thought was going to be a good place to fix this problem. In the codehighlighter.php file, we see:

  1. if ($lang != null) {
  2. $tabstop = 2;
  3.  
  4. $code = trim($matches[5], '\r\n');
  5. $code = str_replace('< /pre>', '</pre>', $code);
  6.  
  7. $geshi =& new GeSHi($code, $lang);
  8. $geshi->set_tab_width($tabstop);

where it's clear in the comments that he's allowing for the special case use of the pre tag, and I decided to try a simple modification of that for these less-than and greater-than signs I'm having trouble with:

  1. if ($lang != null) {
  2. $tabstop = 2;
  3.  
  4. $code = trim($matches[5], '\r\n');
  5. $code = str_replace('< /pre>', '</pre>', $code);
  6. $code = str_replace('\&\l\t\;', '<', $code);
  7. $code = str_replace('\&\g\t\;', '>', $code);
  8.  
  9. $geshi =& new GeSHi($code, $lang);
  10. $geshi->set_tab_width($tabstop);

This is a little odd in the way I have to show it, but it's pretty simple to understand - you replace the HTML escape sequence with the single character in the code. From there, you let the GeSHi engine do it's thing.

What I found was that it worked wonderfully! What a treat. Now I can use either method, and hopefully Daniel will have a fix for MarsEdit sooner rather than later.

The next thing I wanted to tackle with the Code Highlighter was the line numbers. There was far too much space between the lines in a code sample with line numbers. Turns out, there's a style for that in GeSHi. Simply edit the geshi.php file:

  1. /**
  2.   * Line number styles
  3.   * @var string
  4.   */
  5. var $line_style1 = 'font-weight: normal; vertical-align:top;';
  6.  
  7. /**
  8.   * Line number styles for fancy lines
  9.   * @var string
  10.   */
  11. var $line_style2 = 'font-weight: bold; vertical-align:top;';

to be:

  1. /**
  2.   * Line number styles
  3.   * @var string
  4.   */
  5. var $line_style1 = 'margin: 0; font-weight: normal; vertical-align:top;';
  6.  
  7. /**
  8.   * Line number styles for fancy lines
  9.   * @var string
  10.   */
  11. var $line_style2 = 'margin: 0; font-weight: bold; vertical-align:top;';

and the extra border space that the default WordPress theme puts into the li tag will be removed and it'll look much better.

The last little annoyance is the blank lines that start, and end, the code section when you use line numbers. It's just plain annoying. It makes it hard to get the numbers right, and it's whitespace that's not needed. It's a little more involved, but not too bad. In the geshi.php file, you need to change:

  1. // Get code into lines
  2. /** NOTE: memorypeak #2 */
  3. $code = explode("\n", $parsed_code);
  4. $parsed_code = $this->header();

to:

  1. // Get code into lines
  2. /** NOTE: memorypeak #2 */
  3. $code = explode("\n", $parsed_code);
  4. // remove a blank first and last line
  5. if ('' == trim($code[count($code) - 1])) {
  6. unset($code[count($code) - 1]);
  7. $code = array_values($code);
  8. }
  9. if ('' == trim($code[0])) {
  10. unset($code[0]);
  11. $code = array_values($code);
  12. }
  13. $parsed_code = $this->header();

Now I can imagine a way that might be a little more efficient, but I'm not worried at this point. It's not all that bad, and it's very solid. If the first or last lines are empty of code, they get removed and the array is re-indexed. Simple.

With this, I have a really nicely workable solution for my code. Nice.

Google Chrome (dev) 5.0.396.0 is Out

Tuesday, May 11th, 2010

This morning I noticed that Google Chrome 5.0.396.0 (dev) was out and since I've been using Chrome for a week or so now, it's nice to stay up to date as this guy is evolving pretty darn fast. I can't say as I noticed anything bad, but I didn't notice anything, and that's good too.

Google Chrome dev 5.0.375.29 is Out

Tuesday, May 4th, 2010

GoogleChrome.jpg

This morning I noticed that Google Chrome dev was updated to 5.0.375.29 and with it are a few more improvements in the V8 JavaScript engine and the typical stability and security fixes. I have to say, Chrome is getting to the point that it's supplanted Firefox as my backup browser. And when I say backup browser I really mean that it's my second browser that I always run with my hosting service pages always loaded - just in case. So you could think of it as my primary HostMonster browser.

It's fast, it's gotten rid of the problems with a page crashing taking down the entire browser... and the connectivity issues I noticed. It's solid, stable, and while it may not have all the bells and whistles of some browsers, or even the stability of Safari, it's good. Good enough for my second choice.

Getting Clojure Set Up for Snow Leopard

Friday, April 30th, 2010

Clojure.jpg

This morning I had time to spend a bit getting Clojure set up on my MacBook Pro. I have started reading the Pragmatic Programmer book Programming Clojure, and I wanted to be able to start playing with the examples in the book. So I did what any tech guy would do - I Googled to see if anyone had done this already. Simple.

I found this page where he installs just the required jars into ~/Library/Clojure, and after looking at the extent of the installs, it seemed reasonable to try this install method as opposed to what I might have normally done. I ended up getting version 1.1.0 of Clojure which was the latest release version on the site.

Personally, I'd have probably put the Clojure, JLine, and Clojure-contrib installs into /usr/local and then soft-linked them to their non-versioned names. From there, I'd have probably made a similar script, and put it in ~/bin - as he suggests linking to. It's not that big a difference what he's suggesting - it's just keeping it all in one place. Fair enough.

I will say that I did not need to build clojure-contrib as that's now available from Google Code. But other than that, the page was spot on.

I will say I'm stunned that there's no "exit" from the clojure.main run-loop. You have to type:

  user=> (System/exit 0)

to get out. Or, just hit Ctrl-D. This is even referenced in the book. Wild, but hey... that's what they wanted to do.

Now I can play with Clojure and see what all the hub-hub is about.

Google Chrome dev 5.0.375.23 is Out

Thursday, April 29th, 2010

This morning I noticed that the Google Chrome group released another set of versions of their browser, and this time they fixed the Java plug-in issues, and found that the last two previous releases had significant speed issues that are now cleared up.

I say, it's getting better, and I've decided to try it as a replacement for Firefox for a while to see if it's able to best my second-favorite browser. So far, it's looking very respectable. Nice to see.

Decided to Pick up Books on Groovy and Clojure

Friday, April 23rd, 2010

Given the way things have been heading at The Shop lately, I thought it would be a good idea to pick up a book on Groovy and another on Clojure. I didn't know nearly enough about them to be efficient and proficient with them, and I have a feeling that if things continue to develop as they have, I'll be needing them sooner, rather than later.

I have heard a little about Clojure, and it's an interesting take on solving the concurrency problem with software. I can see why it's popular, and it'll be interesting to see it in action, but Groovy was a complete mystery to me.

After the first few pages, I can see it's a Ruby-style of language with extensions to any and all objects. Looks interesting. I haven't done a lot with Ruby, and as Groovy is Java-based, it should work well into what I do. We'll have to see.

Anyway... picking up new tools is always fun.

Upgraded to Git 1.7.0.3 on MacBook Pro

Thursday, April 22nd, 2010

gitLogo.gif

I was reading a few tweets from GitHub today and saw that they had a few new features that need Git 1.6.6+, and it got me to wondering: What version am I on, and what's the latest? I thought I was on 1.6.5.something, but I wasn't sure. So I decided to check. Simple enough.

Because I had tried the "build it yourself" for Mac OS X 10.3.9, I knew that with 10.5, I'd used the git-osx-installer that's hosted at Google Code. I looked there and saw that the 'current' version was 1.7.0.3, and I did a simple:

  $ git --version
  git version 1.6.5.2

OK... we have some work to do.

I got the package from Google Code, and then simply installed it. I'd done it before, so I didn't have to worry about the MANPATH and other things, I just needed to update it.

Now I get:

  $ git --version
  git version 1.7.0.3

and I can take advantage of the new features on GitHub.

I just need to remember to update my machines at home as well. Gotta do that tonight.

UPDATE: Interesting... according to the Git website, the "current" version is 1.7.0.5. That's OK, I'm a lot more current with 1.7.0.3 than 1.6.5.2.

Flash Player 10.1.53.7 Release Candidate is Out

Thursday, April 8th, 2010

This morning I noticed that the Flash 10.1 Release Candidate was out - 10.1.53.7. While I typically use ClickToFlash to not view Flash in Safari (my primary browser), when I have to use it, I want to make sure that it's the best and latest version of Flash. This branch of Flash is supposed to be much better performing on Mac OS X, and it's about time - the vast majority of creative professionals are on Mac, why hasn't Adobe made Flash a top-notch player on the Mac?

Well... it's here, and for all I need, it'll do nicely.

Google Chrome 5.0.366.0 (dev) is Out and Looks Nice

Wednesday, April 7th, 2010

GoogleChrome.jpg

I fired up Google Chrome this morning and noticed that it seems to update itself on each start-up, if necessary. A nice feature, to be sure. The current release is 5.0.366.0 (dev) and I have to say that a lot of my previous concerns about Chrome are slowly, but surely, starting to disappear as the browser matures.

Isn't that always the case? Getting the basics is relatively easy. Getting it polished, well... that's another thing entirely. My latest concerns were really focused on the responsiveness of the browser. It seemed to take a lot longer to get the data from the server than, say, Firefox or Safari. I'm not sure if they have done anything special with the sockets, or if their "every page a process" scheme is causing some additional overhead that the other two don't have, but there was a definite lag in Chrome that wasn't in the other two.

Thankfully, 5.0.366.0 (dev) seems to have cleared up a lot of this. It's actually about on par with Firefox now. Very interesting. I may have to use it for a day or two to see what it's like in more significant usage.

Firefox 3.6.3 is Out

Monday, April 5th, 2010

Sometime this "iPad Weekend", (turns out it was Friday) Firefox 3.6.3 was released with more security fixes that could have led to remove code execution. Standard stuff, but good to see it's still plugging these holes.