1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

convertEditorHtmlToBbCode converts multi-line, why?

Discussion in 'XenForo Development Discussions' started by tenants, Mar 5, 2014.

  1. tenants

    tenants Well-Known Member

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

                            $cell = "three
                                    of string";
                            $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:

    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: Mar 5, 2014
  2. cclaerhout

    cclaerhout Well-Known Member

    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:
          $cell "<p>three</p>
      <p>of string</p>"
    2) Or this:
           $cell "three<br />
      lines<br />
      of string<br />"
    3) Or this:
      $cell "three
      of string"
    $cell nl2br($cell);
    (same than above)
    tenants likes this.
  3. tenants

    tenants Well-Known Member

    $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
  4. cclaerhout

    cclaerhout Well-Known Member

    But what is the source ? The wysiwyg editor or a textarea ? If it's the rte editor, you should not have to do that.
  5. tenants

    tenants Well-Known Member

    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: Mar 6, 2014

Share This Page