Page 1 of 1
Online PHP editor with Syntax coloring
Posted: Mon May 15, 2006 3:09 pm
by Todd_Z
is there anyway that I could create ( or use an already existing ) script to have an area for text, and when you type it colorizes it?
I essentially want to have a javascript equivalent for highlight_file() but fear it will be rediculously slow to update.
Any ideas?
Posted: Mon May 15, 2006 3:10 pm
by Burrito
d11 started one a while back. Not sure how far he got with it, but if I remember correctly in the few times I tried it, it was relatively slow.
Posted: Mon May 15, 2006 3:13 pm
by Todd_Z
I mean slow is inevitable.... but decently slow I can deal with.
The purpose is that I'm creating an intense CMS - and want to allow myself to include php, but i love the colorization.
Posted: Mon May 15, 2006 3:32 pm
by Todd_Z
I just checked out d11wtq's code - its not exactly what I meant - i want to colorize php text, in a browser window.
So as you type in the source code, it would automatically colorize it for you.
I was thinkin that if the idea fails, I could always just wait for a lag in the programming and then send a query via ajax to get the highlighted string format.... i was hoping it wouldn't come to that.
Posted: Mon May 15, 2006 3:34 pm
by Burrito
the code I'm thinking about that d11 wrote, did exactly that. as I said, he may not have finished it and may not have made it public. This was quite some time ago (over a year or so).
Posted: Mon May 15, 2006 3:48 pm
by Chris Corbyn
I did start one yes - I don't have the code any more though since it got obliterated in a hard disk failure
It worked nicely up until about 100 lines of code and then it started to get slower and slower and an incredible rate. The problem was that I was using JavaScript and re-tokenizing and parsing the entire code on each keypress - amateur to say the least.
If I were to do this now I'd go down the AJAX route. I'd have Ghesi installed on the backend and every 2 seconds I'd send the code the server for highlighting. I'd also have it so that if you don't press a key for 500ms AJAX send an XMLHttp request. This would be far faster than my 100% javascript version
To answer your question if there's one available - not that I know of.
I'm actually going to be writing one some time over the next few months but I'll be using the method above.
You'll want to look into how RTE's work if you want to try this yourself

Posted: Mon May 15, 2006 6:42 pm
by Todd_Z
Unfortunately I don't have any time to put together a project like that at the moment, but if you need any help, lemme know
....and what is ghesi?
Posted: Mon May 15, 2006 9:35 pm
by alex.barylski
Weird...as I was just thinking about this today...
I have some ideas for optimization...but basically you would need to regex or tokenize using hand crafted code and wrap keywords, etc in appropriate tags w/ CSS and so on...
Although I can't say I'm totally keen on sending PHP to the server for colorization...and getting back for display...although it's likely slightly faster than regexing every key stroke...the fundamental problem is the colorizing on every keystroke...
Having written a colorizing editor from scratch and even hacking the Windows default text editor to display hyperlinks, I can speak from experience and say that your greatest code bottlenecks come from regenerating a display when not nessecary...
When you write one from scratch...you have total control over which characters get rendered and which don't...you cannot control this in javascript to emulate this technique...but the savings would make a huge difference...
Basically (in JSCript) you would only regex those characters which fall within the current viewport, excluding characters which are not visually rendered....thats likely why d11's version did ok until about 100 lines of code...after which it starts bogging down...
Although, thats a poor metric, as CPU and memory available make a huuuuge difference in anything rendering on the device context of a window...
Basically, you need to reduce the amount of strip/rewrite HTML as possible...as that will make the biggest difference...I'm looking into some ideas as we speak...
Cheers

Posted: Mon May 15, 2006 10:50 pm
by Todd_Z
Sounds like a group project to me. Who knows... maybe this could someday be part of a phpBB script.

Posted: Mon May 15, 2006 11:11 pm
by RobertGonzalez
Todd_Z wrote:....and what is ghesi?
Generic Syntax Hilighter. It the app used on these forums when you select fromt he Syntax... select box. It highlights various versions of programming languages using PHP.