views:

786

answers:

2

PROBLEM: I use Drupal with a rich-editor, and the rich editor likes to clobber my text by stripping out the indentation and formatting. This would be unacceptable in a desktop editor, but people seem to tolerate this with in-browser wyswigs.

QUESTION: How do I turn this off. I've searched around and I have yet to discover the best practice way of telling the rich-editor to preserve my indentation and text formatting.

+1  A: 

The reason that this is happening is the rich-editor is actually an xhtml editor. In xhtml, most tags will (with the exception of the PRE tag), by default, merge multiple whitespace characters to a single space.

To overcome this in tinyMCE, you will need to create a stylesheet containing:

* {white-space: pre;}

And reference the stylesheet as content_css when initializing the editor. Be aware that while you will be preserving your format, it will not be WYSIWYG any more, due to the nature of HTMLs whitespacing munging.

Another option is to wrap your code in a PRE element, but there is no button to do this by default in tinyMCE (or so I believe).

EDIT:

As mentioned by mikl, tinyMCE also has a configuration option for preformatted

Matt
+1  A: 
mikl
That's definitely a pretty screenshot. Unfortunately, it does not work, at least not for me. As soon as the "rich editor" invokes on the browser textarea, the markup inside the GUI control is instantly stripped of spaces and rendered as the dreaded "single line of HTML with no whitespace preservation at all".
dreftymac
+1 I can't believe ive overlooked that preformatted configuration option before! Thank you for that gem!
Matt
No it doesn't work for me either. I wonder why not...
Christopher Edwards