By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,630 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,630 IT Pros & Developers. It's quick & easy.

Syntax highlighting in TEXTAREA - possible?

P: n/a
Nic

Hi - I am battling to find the a resource, so maybe some one in here can
help

The problem is as follows: I am trying to build a mod_perl source code
editor for the web - to edit Perl source code in a browser. The trick is
that I want to add syntax highlighting
to a HTML TEXTAREA tag. There are millions of resources for just normal
text color and background colors (and images), but nothing on keyword
highlighting.

Any help will be appreciated.

O yes - this is for an Open Source project I am planning

Cheers

Nico

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Oct 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


Nic wrote:

The problem is as follows: I am trying to build a mod_perl source code
editor for the web - to edit Perl source code in a browser. The trick
is that I want to add syntax highlighting
to a HTML TEXTAREA tag.


The HTML 4/XHTML 1 textarea control is a plain text edit control so
there is no way to have some characters or words in that control
highlighted. Some browsers (IE/Win, Mozilla since 1.4, Opera since 8.0)
by now allow script to manipulate the selection in a textarea so there
you can use script to select some text in the textarea.

If you want to build a Perl source code editor with syntax hightlighting
then you need to look into editable HTML elements which some browsers
implement, IE/Win (since IE 5) and Mozilla since 1.4 (and Opera 9.0
Preview 1) allow editable iframes where you can set the designMode
property of the document object to 'on' with script and then the user
can edit the current document in the iframe and script can of course
manipulate that too.

See <http://www.mozilla.org/editor/midas-spec.html> for the Mozilla
documentation on that. msdn.microsoft.com has the specification for IE/Win.

IE 5.5 and later on Windows additionally support editable elements in a
document by setting e.g.
<pre contentEditable="true">
so that way you do not need a complete iframe but can have part of your
document editable.

That way you can do your syntax editor with editable markup and CSS.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.