Page 1 of 2
Javascript Rich Text Editor w/ Syntax Highlighting
Posted: Tue Jan 10, 2006 3:31 am
by jayshields
I'm wanting to take my file management system to the next level by adding a file editor, this wouldn't be so hard, as I'd just check the MIME type and if it contains "text", show the text in a HTML textarea and let it be editted and overwritten.
Then I got an idea. This sort of thing would enable me to code via a browser, and as soon as I click save, it will be online and ready to test; like working on a local development server. I found a file manager that already does all the above stuff, and it's very good, apart from it's hard to code PHP (or infact anything) without decent syntax highlighting.
I know there are scripts around to display PHP (and other languages) with syntax highlighting, but I'm looking for something that will display PHP (and possibly other languages if it goes well) in some sort of JavaScript (or AJAX) rich text editor. The syntax highlighting will ofcourse need to be dynamic, hence the need for a client side element.
Does such a thing already exist? I imagine it would be out of my reach to code something like this from scratch.
Thanks.
Posted: Tue Jan 10, 2006 3:33 am
by Jenk
the idea of having the code display in a textarea is for you to copy it to a text editor of your choice, then paste it back when you want to save.

Posted: Tue Jan 10, 2006 3:42 am
by jayshields
That defeats the object though
I want it to sort of simulate working on a local development server, so I can just bring up syntax highlighted code, edit it, click save, and refresh the URL.
So is there no such thing?
Posted: Tue Jan 10, 2006 3:59 am
by Jenk
is it possible to change colours in a textarea?
And it doesn't defeat the object at all.. it just doesn't achieve what you want it to achieve

Posted: Tue Jan 10, 2006 5:15 am
by jayshields
You can change the text colour in a textarea, but only the whole area at once, as far as I'm aware. I don't know how they do it in those online Rich Text Editors.
Not achieving what I want it to achieve and defeating the object are the same things as far as I'm concerned

Posted: Tue Jan 10, 2006 5:29 am
by Maugrim_The_Reaper
I assume they're using lots of <span></span> tags with specific styles attached for changing colours. The output is still part of an HTML doc afterall...
Posted: Tue Jan 10, 2006 6:38 am
by pilau
That's such a magnificent idea, Jay. It's very nice. I tried to search something for you but to no prevail so far.
And as far as I'm concerned you can't have multiple colors for text in a textarea.. Sorry to ruin the party.
Maybe you could put each different-colored-text in a text field?

Posted: Tue Jan 10, 2006 7:08 am
by jayshields
I think putting seperately coloured text in different fields would spoilt it a bit.
I'm sure there is a JavaScript Rich Text Editor somewhere, I mean, some of the CMS's I've heard about have Administration pages where you can use an in-built WYSIWYG editor, that must be close to what I want.
Originally, the only problem I thought I would have was implementing a syntax highlighter, because I doubt I could code one, so I would need to find an open-source one, and I thought an existing PHP syntax highlighter (not meant for editting, only displaying) could be adapted with a bit of work.
I've just found one on Dynamic Drive:
http://www.dynamicdrive.com/dynamicinde ... exteditor/
I knew there were such things already, but I don't really want all that functionality, that link just proves Rich Text Editors are available.
Posted: Tue Jan 10, 2006 9:15 am
by John Cartwright
Originally, the only problem I thought I would have was implementing a syntax highlighter, because I doubt I could code one, so I would need to find an open-source one, and I thought an existing PHP syntax highlighter (not meant for editting, only displaying) could be adapted with a bit of work.
Look around our code snipplet board, we have one around somewhere

Posted: Tue Jan 10, 2006 9:32 am
by pilau
jayshields wrote:I think putting seperately coloured text in different fields would spoilt it a bit.
I was joking.
jayshields wrote: [...] I would have was [...]
Can you say that in English?? "I would have was", is that ok grammer-wise? I mean, what tence is it?
Posted: Tue Jan 10, 2006 9:44 am
by Weirdan
And as far as I'm concerned you can't have multiple colors for text in a textarea.. Sorry to ruin the party.
However it's possible to edit an iframe (
http://developer.mozilla.org/en/docs/Ri ... in_Mozilla )and then on form submit load the innerHTML of that iframe into some hidden field. After running strip_tags on the received data you should get proper plain text (without the html tags that were used on client-side to colorize the source)
Posted: Tue Jan 10, 2006 9:47 am
by Weirdan
pilau wrote:
jayshields wrote: [...] I would have was [...]
Can you say that in English?? "I would have was", is that ok grammer-wise?
He said that '...he thought he would have a problem, the problem was....'
I mean, what tence is it?
It's... hm... feature-in-the-past perhaps.
Posted: Tue Jan 10, 2006 10:42 am
by Jenk
It's very tense, temple vein throbbing tense. (I know it's a different spelling, but I am bored dammit.)
Posted: Tue Jan 10, 2006 10:45 am
by pilau
Weirdan wrote:pilau wrote:He said that '...he thought he would have a problem, the problem was....'
Oh, now I get it thanks a lot! I can't believe I didn;t realize it on my own,

Posted: Tue Jan 10, 2006 1:45 pm
by jayshields
lol I just read your post and thought, hhmm, not usually like to me to use bad grammar, read over my post, and you did misinterpret it a little.
It's only a forum anyway, I cna tpye hwo i wana ok!?