convertEditorHtmlToBbCode converts multi-line, why?

tenants

Well-known member
Can anyone see what it is about convertEditorHtmlToBbCode that converts multi-line text into single line


Code:
                        $cell = "three
                                lines
                                of string";
               
                        var_dump($cell);

                        $cell = $this->getHelper('Editor')->convertEditorHtmlToBbCode($cell,  $this->_input); // now safe for raw

                        var_dump($cell); // multi-lines getting converted to one line

This out puts:

three
lines
of string

three lines of string


The reason I want to use convertEditorHtmlToBbCode directly (instead of ->getMessageText) is that my data comes in from an array (in this case it has to)

So, I can't use "getMessageText($inputName, XenForo_Input $input, $htmlCharacterLimit = -1)"

Since my message is not an inputName in the XenForo_Input, it is part of

$this->_input->filterSingle('fields', XenForo_Input::ARRAY_SIMPLE)
 
Last edited:
This is normal. The helper converts html string to bb code string ("normal" text box string with \r\n, etc.). In html, the \r\n carriage return doesn't exist, so the helper ignores it and return the string in the same line.

You've got different solution to get your lines breaks.

1) Use this:
PHP:
      $cell = "<p>three</p>
  <p>lines</p>
  <p>of string</p>";

2) Or this:
PHP:
       $cell = "three<br />
  lines<br />
  of string<br />";

3) Or this:
PHP:
  $cell = "three
  lines
  of string";
  
  $cell = nl2br($cell);
(same than above)
 
$cell = nl2br($cell);

That's not a bad idea, I wonder if I will run into any other issues by bb-encoding on insert, rather than on rendering

These are not Editor areas, (usually just single lines) so they will usually only have a small amount of text,

thanks @cclaerhout
 
Usually a single line of text, sometimes a text area (not the rte editor)

I've decided against it, I'm going to insert without bb encoding, just input->filter (as threads/posts do), then I'm just going to update my view so that the rendered text passes through the getBbCodeWrapper for each text area (as thread/posts do).

It's trickier than doing this with threads/posts since I have lots of areas, but I should try to be consistent with the core (they don't bb-encode on insert)
 
Last edited:
Top Bottom