Online PHP editor with Syntax coloring
Moderator: General Moderators
Online PHP editor with Syntax coloring
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?
I essentially want to have a javascript equivalent for highlight_file() but fear it will be rediculously slow to update.
Any ideas?
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.
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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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
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
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
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
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
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.Todd_Z wrote:....and what is ghesi?