Not a bug Editor's list functionality doesn't behave as expected after editor content replaced with XF.replaceEditorContent

MilkyMeda

Active member
Affected version
2.1.7
My JS handler when insterting HTML into editor:
JavaScript:
if (data.htmlText) {
                this.editor.ed.undo.saveStep();
                XF.replaceEditorContent(this.$form, data.htmlText);
                this.editor.ed.undo.saveStep();
                this.editor.focus();
            }

After replacement, this bug occurs:


I render the posted BBCode as follows:
PHP:
$htmlText = \XF::app()->bbCode()->render();
 
Can you provide a more detailed reproduction case?

What is the value of dara.htmlText that is problematic? What is output? What are you expecting?
 
The output is what the BBCode renderer returns. Example:
HTML:
<div class="bbWrapper">Example line 1<br />↵Example line 2</div>
Now try to add unordered list to the second line. It will add it to the first line.
 
Before sending it to the BBCode renderer? This:
JavaScript:
htmlText: "<div class="bbWrapper">Line1<br />↵Line2</div>"
originalText: "Line1↵Line2"
Notice the character ↵ is a line break.
 
I think this is mostly expected.

The primary issue here is that we don't actually use <br /> tags to denote a line break. We have the editor configured to wrap lines in <p> tags.

If it was inserted as <p>Line 1</p><p>Line 2</p> it would work as expected.

The editor would behave differently, I think, if we had the BR mode enabled.

The conversion from HTML to BB code produces:
Code:
Line 1
Line 2
Converting that back to HTML demonstrates the expected format.

In essence, the previous bug you pointed to was because we weren't converting to that expected format on paste. We were pasting in the <br /> line breaks as is, but now the behaviour is that we convert them to be enclosed in <p> tags.

You will see a bunch of this handling in XF.editor.editorInit() but it is specific to our paste handling and so you may want to handle it differently. If you're able to, it might be worth converting to BB code and then back again. It's a slightly roundabout way of doing it, but it produces the right output.
 
Removing the wrapper alone fixed it. It didn't need any conversion.
PHP:
$htmlText = preg_replace('#<div class="bbWrapper">(.*)</div>#uis', '$1', $htmlText);
The editor doesn't like inner divs 😏
 
Given that you mention how you're rendering the BB code, I think the problem is just that you're using the wrong renderer. You should be using the "editorHtml" renderer if you're trying to render for the RTE.
 
Top Bottom