Online PHP editor with Syntax coloring

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Online PHP editor with Syntax coloring

Post 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?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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).
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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?
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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 :)
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Sounds like a group project to me. Who knows... maybe this could someday be part of a phpBB script. 8O
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply