cfCodePress - Custom Tag For Real Time Code Coloring

Posted By : todd sharp Posted At : July 5, 2007 11:50 AM Posted In: cfCodePress, ColdFusion

7

Over the past few days I've thrown together a custom tag implementation of CodePress.

Here's an abbreviated description of CodePress taken from their site:

CodePress is web-based source code editor with syntax highlighting written in JavaScript that colors text in real time while it's being typed in the browser.

Features

  • Real-time syntax highlighting » just write some code
  • Code snippets » on PHP example type "if" and press [tab]
  • Auto completion » simple type " or ( or ' or [ or { on any example below (except Plain Text)

What makes this tag cool is that you can now drop a nicely formatted block of code or a real time syntax highlighting code editor into your application with a single line of code.

Check this out (go ahead, type some code):

Update: Arg...Demo appears to not work here after the first time I hit the page...

Check this demo instead...

Update 2: OK...it works intermittently here in the blog post...weird...


There are a few bugs with it - which is why I'm just previewing and not releasing the tag just yet. First and most obviously you see that when I drop my demo page as an include in BlogCFC the editor does not seem to be obeying the line breaks in the code I load initially into the editor. Check out the demo outside of my stylesheet to see a properly formatted block (anyone see anything in my stylesheet that could be goofing it?).

Secondly - I've integrated the CodePress SQL, HTML and CSS templates into the CF version - and it tends to get a little goofy. For example type a comment with an SQL keyword in it and it will highlight the SQL keyword. Anyone really good with RegEx that wants to take a look at overcoming these issues?

There is also an API to toggle line numbers, etc that I plan on exposing with the final release of the code.

Comments (7)

Boyan's Gravatar Pretty neat...or at least on the way there, he he. You should talk to Ben Nadel about the RegEx - he is pretty damn good at it.

Ben Nadel's Gravatar My ears are burning... did some mention my name???

todd sharp's Gravatar Hey Ben - did you get my email on this last night?

todd sharp's Gravatar You probably didn't get the email about this comment since it threw an SMTP error....

sheesh..

Ben Nadel's Gravatar I sent you a response... did you get that one? My GMail hosted email is funny sometimes I think.

todd sharp's Gravatar Yeah I got it - cool - thanks!

ivan's Gravatar very cool

thanks