1

Topic: 3.4 preserving source whitespace

Since upgrading to 3.4 I've been trying to figure out how to preserve any custom whitespace formatting in the source editor.

We had these options in 3.3 which worked out fine:
apply_source_formatting : false
remove_linebreaks : false

'preformatted : true' sounds like its what I need, but  from what I can tell its not working. Anyone have any ideas?

2

Re: 3.4 preserving source whitespace

Preserving white space in a rich text editor will never work. Just think about it, it would need to have some form of AI to figure out how the current document is formatted with white space and depending on that format apply the same indentation to new contents of the same type or it will be completely random behavior existing contents would be indented for a while until you modify it.

So it's better to just normalize the whitespace/formatting so that it will always be produced in the same way. We do that by removing all white space before after block elements and some whitespace that is redundant then re-apply line feeds before/after block elements. We don't indent with tabs/spaces since it would produce way to much HTML code for storage. We might add some plugin for that in the future that does the extra indentation.

Best regards,
Spocke - Main developer of TinyMCE

3

Re: 3.4 preserving source whitespace

Thanks spocke, I can understand the difficulty there.

So the remove_linebreaks and preformatted settings are being deprecated in favor of the behavior you described? It's just a little confusing to have them in the docs if they are no longer relevant.

4

Re: 3.4 preserving source whitespace

I don't.  Taking nicely formatted HTML with tabs and crlf in it and removing all this because it takes up too much storage -- makes no sense.  So we should never expect this capability in e near future?

5

Re: 3.4 preserving source whitespace

I can't explain it better than my initial comment. It makes no sense to keep whitespace between nodes in fact it would produce even worse output with random indentation etc.

We might however write a plugin in the future for source code indentation. That removes any existing indentation and re-applies new indentation based on specific settings.

Best regards,
Spocke - Main developer of TinyMCE

6

Re: 3.4 preserving source whitespace

I am not quiet sure whether my problem matches the issue dicsusssed here.

When I edit my source code with TinyMCE, all CRLFs, Tabs and whitespaces get lost. This results in unreadable resp. uneditable source code.

Is this by design or didn't I find the right option yet? apply_source_formatting : true and remove_linebreaks : false did not solve my problem.

--
Greetings from Hannover, Germany
Michael

7

Re: 3.4 preserving source whitespace

MFromH wrote:

I am not quiet sure whether my problem matches the issue dicsusssed here.

It does.

MFromH wrote:

When I edit my source code with TinyMCE, all CRLFs, Tabs and whitespaces get lost.

It's a feature, not a bug.

MFromH wrote:

This results in unreadable resp. uneditable source code.

As spocke has said they might (or might not) create a plugin to solve this problem. At the moment there is some logic to recreate some source code indentation but it is only a rudimentary thing.

MFromH wrote:

apply_source_formatting : true and remove_linebreaks : false did not solve my problem.

Then you will need to "beautify" your source code on the server-side using some third-party library. If you use PHP you might want to try Tidy.

Greetings from Germany,

Felix Riesterer.
-- I am neither Moxiecode nor Ephox! --

8

Re: 3.4 preserving source whitespace

Thank you for your quick reply.

I understand, that I have to decide between coding myself and let TM generate code and never having a look at it any more.

Not too simply for someone, who is used to produce human readable and editable sources since 28 years ;-)

--
BFN
Michael

9

Re: 3.4 preserving source whitespace

spocke wrote:

Preserving white space in a rich text editor will never work. Just think about it, it would need to have some form of AI to figure out how the current document is formatted with white space and depending on that format apply the same indentation to new contents of the same type or it will be completely random behavior existing contents would be indented for a while until you modify it.

So it's better to just normalize the whitespace/formatting so that it will always be produced in the same way. We do that by removing all white space before after block elements and some whitespace that is redundant then re-apply line feeds before/after block elements. We don't indent with tabs/spaces since it would produce way to much HTML code for storage. We might add some plugin for that in the future that does the extra indentation.

My earlier post was a bit more on the critizing area, but luckily our connection dropped.

That answer is just complete bull.
Preserving white space in a rich text editor will never work...
Seeing as you're actually describing an AI, I'm doubting your expertise. It's really not that big of an issue making a renderer, which keeps whitespaces in mind.
It's not like -every- browser out there already does that.

As well as the comment : "We don't indent with tabs/spaces, since it would produce way too much HTML".. Ridiculous!
Yes it takes more space, which is why XML is seldomly a real good choice, but this is obviously something which a developer himself could decide.
Oh nooes I have to save maybe 1 kb more!

Complete webservers will crumble because of this...

It sounds like you're holding back certain features, because of other reasons than the technical ones.
So do not just make up a silly story and refrain from calling yourself a developer or something with those answers.

And by the way I agree that a standardized output is neat, but it should be possible to bypass this. It's not that strange to have such a feature.

As I've seen this kind of stupid answer before (2004?), I don't think it'll ever happen.

10

Re: 3.4 preserving source whitespace

What is the problem with using Tidy to a) clean up and b) format the source code?

Greetings from Germany,

Felix Riesterer.
-- I am neither Moxiecode nor Ephox! --

11

Re: 3.4 preserving source whitespace

While stripping white-space/tabs may be a "feature" and not a bug, it would be nice if there was an option to not do it.  I can't tell you how obnoxious it is when posting code (via CODE or PHP BBCode) and have it strip out all indentation...

12

Re: 3.4 preserving source whitespace

digitalpoint wrote:

While stripping white-space/tabs may be a "feature" and not a bug, it would be nice if there was an option to not do it.  I can't tell you how obnoxious it is when posting code (via CODE or PHP BBCode) and have it strip out all indentation...

Am I missing something here, or can't a simple regex be used to replace all instances of space characters (regular, unicode, whatever) into " "?

I do it on my message board to preserve "tabs" in postings of code blocks.

But since "tabs" (indents) are usually 4 spaces, I only replace "space-space" with "  " to preserve the "tabs" but not place an   into EVERY space (which would be absurd).

That is......

    text = text.replace(/( | |\u00a0){2}/gi,'  '));
"Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov

13

Re: 3.4 preserving source whitespace

That would certainly work for me... now if only I knew where I could add that.  smile

14

Re: 3.4 preserving source whitespace

Whitespace needs to be normalized in a rich text editor since it would otherwise not work properly. No one want's random HTML output indentation so it needs to be forced as I explained before.

We have plans to provide more options for source formatting but we will never preserve whitespace as it is unless it's a PRE, SCRIPT or TEXTAREA element.

Best regards,
Spocke - Main developer of TinyMCE

15

Re: 3.4 preserving source whitespace

I've read this chain of postings ....

Having a WYSIWYG editor is a great benefit for setting up clients in their CMS so that some administrative assistant can enter basic code -- visually.

However, not being able to re-edit the code in the same editor kind of defeats the purpose of the editor. So some admin assistance has a table of information in a page. She needs to edit it. She opens up the HTML source, and all of the white space formatting is gone. No good. She knows from experience that if she just uses the visual interface to insert/modify code, that she is likely to get something "off, just  a little" . Her boss will not be happy.

So, she copies the code out of the editor and pastes into a Dreamweaver blank HTML page. Her, she applies source formatting so she can make heads and tails out of the HTML soup she was looking at before. Ah, there's the row she needs to edit. Change that cell content, add a class here and there. Okay ... done. Now copy out of Dreamweaver and paste back into the WYSIWYG editor. Now save the CMS page.

You might as well just give them a text area box for HTML code and tell them to buy a copy of Dreamweaver. This is always the BIGGEST disappointment my clients express. If you could solve this problem, clients would buy your editor plugin to install in their CMS for $50 - $100 a pop.

I suppose I see some of the technical programs. But, it seems like you ought to be able to maintain two content areas. One area would be for HTML source code and spacing--where all white space is preserved. And the other area would be for visual display of the HTML from the HTML source code space.

Many of my clients would be happy to just "see" the what their code looks like even if they can't edit it visually. Usually, at some point, most corporate marketing admin assistance come to the realization that if they are going to get that page looking just right, they are going to have to know some HTML code. They might "hope" at first that they can do it visually, but they all come around eventually--too many overlapping tags that they just couldn't see. Or table rows get classed instead of table cells. The list of subtle ways to get it wrong just goes on and on until they finally resign themselves to learning some HTML and looking at the code. And then they realize their white space is not preserved. Every time they go back to looking at that page, it's HTML soup. Now they have to ask their boss to purchase an HTML editor.

I cannot tell you how many times I've been through this with clients. I'm telling you, if you solve this you'll make a small mint.

16

Re: 3.4 preserving source whitespace

It's a very narrow use case that says we should NEVER need to preserve white space.

We are managing large libraries of content blocks (each edited separately via TinyMCE). Those blocks then flow together into larger business content combinations for presentation via web and print. Especially in the print output stream, we need leading and trailing spaces to be maintained so that when the smaller content blocks are stitched together, they have the right whitespace between them.

The actual use cases are varied, but the bottom line is, if our users enter a leading or trailing space, they mean it and want to keep it. No,   is not good enough, nor is replacing all spaces with  .

It has been a long time since there was a post on this thread. Any update on the aforementioned options or plugins?

17

Re: 3.4 preserving source whitespace

In my opinion this must be resolved from within the backend, not in the editor.

Greetings from Germany,

Felix Riesterer.
-- I am neither Moxiecode nor Ephox! --

18

Re: 3.4 preserving source whitespace

Whitespace is preserved in elements that are formatted as pre elements. This is by default "pre script noscript style textarea video audio iframe" object elements. Can be re-configured with whitespace_elements.

Best regards,
Spocke - Main developer of TinyMCE

19

Re: 3.4 preserving source whitespace

Spocke, please, would you kindly understand that we are not using TinyMce as you imagined we would?
Then if you say "sorry, I'm not able to comply" it's fine, but don't try to make us understand that we don't really want what we really want.

I support mcollins and carolynv views. I operate wordpress sites, I'm perfectly ok with editing html (as a matter of fact i prefer it since it's more powerful - face it, you can't do everthing with tinymce) but I cannot expect all the editors to become web programmers. Even if they'd do I would need good programmers to keep the code decent. At the same time I cannot afford to have my code mangled each time an editor writes a word in it.

Really, please, let's talk concrete things.
Thank you.

20

Re: 3.4 preserving source whitespace

I found this:

CKEditor forum wrote:

How can I get CKEditor to just leave my bloomin' code alone entirely?!

I'm afraid that's not possible, due to how CKEditor generates the output. It completely rebuilds the source from scratch based on the DOM tree in the editing area each time the
content is requested from it. But, it's possible to control how it formats your markup.

If this is true for TinyMCE you should have stated it a long time ago.
And btw those editors using that technology should be called WYSYWIG DOM editors. An Html editor is another thing.
Good bye