views:

94

answers:

1

I am looking for a web-based JavaScript <textarea> editor with support for standard features like selectable font, text colour, paragraph alignment etc. However, there is one considerable constraint: Formatting should always apply to all the text, not parts of the text. That is, the user is able to colour all of his text red, or all of his text blue, but he shouldn't be allowed to mix and match.

None of the editors I've looked at so far explicitly supported this feature, short of hacking it into the editor. Is any editor out there able to do this out of the box, or with small amounts of configuration?

Thanks a lot for any hints!

+2  A: 

This should be doable by taking any WYSIWYG editor, removing all text formatting capabilities and controlling the document's style by manipulating the body element's CSS:

my_wysiwyg_editor.document.body.style.fontSize = "15px";
my_wysiwyg_editor.document.body.style.color = "blue";

Here's how to access the WYSIWYG document in CKEditor (the top rated answer is the correct one IIRC, I can't accept it because it was an expired bounty.)

I'm not promising it will work out for you, though, and there will be quirks - the editors tend to add their own stuff to the HTML (e.g. wrap paragraphs into <p> tags and such) which could make life hard.

If you wouldn't need some of the WYSIWYG capabilities, I'd suggest a normal textarea - you can influence that in font size, colour etc. easily and it's way simpler than a full-blown WYSIWYG solution.

Pekka
According to the description, I would use just a textarea. Setting its styles will fit with the requirements without any extra worries.
AlfonsoML
Thanks for your input Pekka, a standard textarea was the way to go. Turns out the user input had to be previewable in several custom fonts anyway, and I didn't want to mess with downloadable soft fonts or TTF->SVG rendering.Thus, I'm using a no-frills textarea for the input now and render the fancy preview to PNG using server-side Cairo. Works like a charm and is astonishingly responsive even in near-realtime.
Daniel Werner