Not planned Preserve user-inserted spaces in the editor

jauburn

Well-known member
Poets need a forum editor that preserves user-inserted spaces because the formatting of poetry is often essential to its meaning. So far in the forum software world I have found very few packages that include an editor that preserves user-inserted spaces. Simple Machines is one. However, I much prefer the more robust forum packages in most other respects, and for my longstanding poetry forum for serious writers, I would love to adopt Xenforo. But I can't because, like the editor in vbulletin and many other forum software packages, the editor in xenforo strips all user-inserted spaces when a post is saved.

Is there any hope that xenforo may be in the future for my forum?

Thank you.
 
Upvote 3
This suggestion has been closed. Votes are no longer accepted.
Thank you. So is this a replacement editor for xenforo? And would it allow user-inserted spaces in a post?

To make it simple : there are two kinds of text format, the raw text & the html. The raw text has tabs (character: \t), the html doesn't. Tabs must be then emulated in html. XenForo messages are saved in the database using the raw text. If you use the "Bb Code editor", it is raw text. So tabs are saved with your message. If you use the Rich Text Editor (RTE or Wysiwyg editor), the format is then html. The html message will be converted to raw text by XenForo. You can press as hard as you can the tab key of your keyboard, no tab character will be output. It simply doesn't exist.

So in html, tabs must be emulated: when you save your text and when the message is displayed from the database. "Emulate" is a big word that only means to manually type X white spaces (most of the time 4 white spaces). Some RTE can bind a function that will automatically inserts 4 white spaces when you press the tab key (see TinyMCE). With XenForo 1.1, I'm sure, those 4 white spaces were not converted to a tab inside the database. For XenForo 1.2, I don't know. The TinyMCE Quattro addon has a set of parser tools which come from a previous addon that convert those 4 white spaces into a tab (this is a basic operation) before to save the message in the database. These parser tools are active even if you don't use the TinyMCE editor (which must be activated by usergroups). Since this addon had this function but didn't emulate back the tabs when the message was displayed (what you're asking for), I've just added that function (see message #31) as an option to the set of parser tools.

Now that you've got the background and the needed information, to reply to your questions:
  • If you enable TinyMCE Quattro editor it will replace the default XenForo editor
  • If you enable two of the TinyMCE Quattro parser options, the tabs will be emulated when messages are displayed, no matter you use TinyMCE editor or the default editor.

If you need to target more than tabs, then the use of a Bb Code is needed. If you need to emulate tabs inside a BbCode, I've included an helper to do that in this addon. To use it when you code your BbCode:
PHP:
$bbcodeContent = BBM_Helper_BbCodes::emulateWhiteSpace($bbcodeContent);
 
Last edited:
I activated "Emulate tabs in html?" in your tinymce quattro plugin, and indeed this does not seem to preserve two, three spaces...just four, and that of course won't do for poets. If they line something up using the space bar, they need to see that alignment preserved. This preservation of white space issue is not just about tabs. In fact tabs are the least of the concern of a poet; I imagine they're a legimate concern of normal essay writers, though, who should rightly expect to be able to indent the first line of a paragraph with a tab, just like it's been taught in English class since the dawn of modern-day English classes.

What I find most odd, though, is that the preservation of spaces (not just tabs) seems to be done in this demo of the full version of tinymce. That's exactly what the poets on my board need and want. Plus that little "preview" icon is just super, as are the drop down menus for File, Edit, Insert, and so on. Great stuff. Why can't we have that full editor here?
 
The decision to move away from TinyMCE was made with 1.2, the editor caused quite a few issues with the software.
 
I activated "Emulate tabs in html?" in your tinymce quattro plugin, and indeed this does not seem to preserve two, three spaces...just four, and that of course won't do for poets. If they line something up using the space bar, they need to see that alignment preserved. This preservation of white space issue is not just about tabs. In fact tabs are the least of the concern of a poet; I imagine they're a legimate concern of normal essay writers, though, who should rightly expect to be able to indent the first line of a paragraph with a tab, just like it's been taught in English class since the dawn of modern-day English classes.

What I find most odd, though, is that the preservation of spaces (not just tabs) seems to be done in this demo of the full version of tinymce. That's exactly what the poets on my board need and want. Plus that little "preview" icon is just super, as are the drop down menus for File, Edit, Insert, and so on. Great stuff. Why can't we have that full editor here?
I've replied to you in the addon topic and by pm (about the "full editor"). To sum up: white spaces are preserved inside the editor but are not rendered once the message is displayed.

The decision to move away from TinyMCE was made with 1.2, the editor caused quite a few issues with the software.
One more time, this information is not correct. Put aside one bug because of an outdated version of MCE, that was the software which caused issue with the editor. The XenForo parser/formatter was incomplete with XenForo 1.1 and Mike fixed this with XenForo 1.2. While most people was busy at complaining about the initial grey design of XenForo Redactor, nobody cared about the most important part. This incorrect information spread by XenForo users that MCE was buggy even went to XenForo competitor forums... A strange way to thank MCE developers for their opensource script.
 
It is not incorrect information. The TinyMCE implementation caused quite a few issues and was the catalyst for the decision to change.
 
I'd just really like to see the needs of users put before the needs of software. This is not a radical concept.
The needs of the software relate directly to the needs of the users. It is not a radical concept that with a buggy editor implementation and a difficult API for the developers to use, that a change benefits the customers in more ways than one.
 
The needs of the software relate directly to the needs of the users.

You'd have to show me how that's true. From this user's perspective, the xenforo input system simply doesn't accommodate some very basic needs of writers (e.g., the need to use tabs) or of creative writers (e.g, the preservation of all user-inserted spaces, the subject of this thread). Nor do I see a way to insert special characters--em dashes or en dashes, just to name two of dozens that writers might need.

Basically what we have here is a rudimentary straight text HTML editor that's good for doing what you and I are doing here now, exchanging ideas where the formatting of the text in which those ideas are housed makes no difference whatsoever.

Get users that are a bit more demanding about the presentation of their text, though, and the best you can do with this editor is suggest that those ideas be presented as graphics. Bummer. And not acceptable. I don't call that user-friendly. Remember, most users aren't programmers.
 
Last edited:
No, he could have inserted the spaces perfectly fine with this editor. They would have been preserved with this editor. Your qualms are not with the editor... Your qualms are with standard HTML specifications:
http://xenforo.com/community/threads/preserve-user-inserted-spaces-in-the-editor.54761/#post-583913

I think we're just arguing without hearing what each other is saying. Cummings would have been fine with this editor? How? In no way that I can see.

My qualms are with HTML? Perhaps. But how did the SMF forum (and a couple of others) manage to include editors that preserved user-inserted spaces? You see, users don't really care about the limitations of technologies. Only geeks do. Geeks justify the way things work because "that's the way the technology forces it to work." User don't care about this stuff. Users want stuff to work the way that intuition says it should work. End of sentence. (What you want to do is change intuition to match technology.) Apple is successful because it purports to understand this. Whoever understands this wins.
 
Last edited:
Yes, you can insert spaces perfectly fine with this editor. If E.E. Cummings wanted to type and place all his spaces in, they would have been kept.

If you would just explain how this is possible, I would be a very happy/content person right now. What you say is possible, though, simply isn't. Here, let me try (and I hope I end up eating my words):

This line has no spaces before it.
This line has two spaces before it.
This line has three spaces before it.
This line has four spaces before it.
This line has five spaces before it.
This line has eighteen spaces before it.
 
Look at this. How are poets going to do this by pasting text in to the xenforo editor? I'm trying to convert away from SMF, but I can't until this issue is solved for the members. Entering a poem as "code" just doesn't cut it.
 
It is not incorrect information. The TinyMCE implementation caused quite a few issues and was the catalyst for the decision to change.
This is incorrect information, but it seems useless to continue this talk.

@jauburn
The solution of your problem:

PHP:
  public function emulateAllWhiteSpace($string)
   {
     return preg_replace_callback(
       //The below regew will match whitespaces (start from 2 and exclude the last one of a line) + exclude match if a ending html tag is detected
       '#[ ]{2,}+(?<! $)(?![^<]*?>)#',
       array($this, '_emulateAllWhiteSpaceRegexCallback'),
       $string
     );
   }
   
   protected function _emulateAllWhiteSpaceRegexCallback($matches)
   {
     $breaksX = substr_count($matches[0], " ");
     $breakPattern = '&nbsp;'; //other possible UTF8 solutions = http://www.cs.tut.fi/~jkorpela/chars/spaces.html
     $breakOutput = str_repeat($breakPattern, $breaksX);
           
     return "{$breakOutput}";
   }
 
This is incorrect information, but it seems useless to continue this talk.

@jauburn
The solution of your problem:

PHP:
  public function emulateAllWhiteSpace($string)
   {
     return preg_replace_callback(
       //The below regew will match whitespaces (start from 2 and exclude the last one of a line) + exclude match if a ending html tag is detected
       '#[ ]{2,}+(?<! $)(?![^<]*?>)#',
       array($this, '_emulateAllWhiteSpaceRegexCallback'),
       $string
     );
   }
 
   protected function _emulateAllWhiteSpaceRegexCallback($matches)
   {
     $breaksX = substr_count($matches[0], " ");
     $breakPattern = '&nbsp;'; //other possible UTF8 solutions = http://www.cs.tut.fi/~jkorpela/chars/spaces.html
     $breakOutput = str_repeat($breakPattern, $breaksX);
         
     return "{$breakOutput}";
   }


Thank you! But how do I implement this solution? I bow at your feet for the simple instructions. Showing me some php code and assuming I know what to do with it/where to put it is to put me in the class of developers, and I am not.
 
and here's another example. Try to reproduce that here. Ugh.

thumbs-down.jpg
 
Top Bottom