Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKeditor is mangling inline plugins with multiple <p> tags #454

Closed
mailbackwards opened this issue Jan 10, 2018 · 4 comments
Closed

CKeditor is mangling inline plugins with multiple <p> tags #454

mailbackwards opened this issue Jan 10, 2018 · 4 comments

Comments

@mailbackwards
Copy link

mailbackwards commented Jan 10, 2018

I have a RawPlugin inside of CKEditor where I hope to keep raw HTML and avoid CKEditor changes. Most content works fine, including content inside a single paragraph tag, e.g. <p>Foo</p>. But if I add a second graf, e.g. <p>Foo</p><p>Bar</p>, and then toggle once between the Source and Edit views, it moves the p tags around and mangles the tags.

After initially adding it (this is "correctly" formatted):

<p>One</p>

<p><cms-plugin alt="  Raw - A
B&lt;... " id="250" render-plugin="true" title="  Raw - A
B&lt;...">
<p>A</p>

<p>B</p>

<p>C</p>
</cms-plugin></p>

<p>two</p>

<p>three</p>

<p>four</p>

<p>five</p>

After next toHtml event:

<p>One</p>

<p><cms-plugin alt="  Raw - A
B&lt;... " id="250" render-plugin="true" title="  Raw - A
B&lt;..."></cms-plugin></p>

<p>A</p>

<p>B</p>

<p>C</p>

<p>&nbsp;</p>

<p>two</p>

<p>three</p>

<p>four</p>

<p>five</p>

This seems to happen regardless of whether or not the plugin is wrapped in its own <p> tag. I believe this is happening on step 5 of toHtml, as it goes through the BEFORE_MARKUP_PARSED event without any trouble.

Any advice on how to cancel this out? Is there a way to skip this or other markup changes within <cms-plugin> tags, so that it can be truly raw HTML, even if it doesn't render perfectly?

I'm on Django==1.11.9 and djangocms-text-ckeditor==3.5.1rc4

@vxsx
Copy link
Contributor

vxsx commented Jan 15, 2018

There seems to be a bug on our end, since that should unwrap into this (normally):

<p></p>
<cms-plugin alt="  Raw - A
B&lt;... " id="250" render-plugin="true" title="  Raw - A
B&lt;...">
<p>A</p>

<p>B</p>

<p>C</p>
</cms-plugin>
<p></p>

I'm looking into why it happens.

In the meantime to fix it you can add text_editor_preview = False to the RawPlugin class. It won't mangle the markup but there will be no preview

Otherwise there's no way to opt out of things we do to have inline previews of plugins

@vxsx
Copy link
Contributor

vxsx commented Jan 15, 2018

Interestingly enough - I can't reproduce this, for me it successfully unwraps into:

<p>&nbsp;</p>
<cms-plugin alt="Snippet - test " id="22" render-plugin="true" title="Snippet - test">
<p>A</p>

<p>B</p>
</cms-plugin>

<p>&nbsp;</p>

Is there any additional ckeditor configuration used?
Does it happen for you in all browsers? (browser's mechanism is used to unwrap <p> tags)
What are your CKEDITOR_SETTINGS in your settings.py?
Is it possible for you to provide access to a minimal project where I can reproduce it?

@vxsx vxsx self-assigned this Jan 15, 2018
@mailbackwards
Copy link
Author

I think I've now figured this out... it has to do with the __str__ method on the plugin. Apparently the way it was rendering left half a <p> tag in the markup in many cases, even though it's escaped (you can see the &lt; up there in my original message). That must be confusing the parser-- if I strip out all tags before rendering it works.

So I think that's the fix-- I'm glad to have it, and thanks for testing it out!-- is there something that can be done in the code or docs to fix or alert users about it? Thanks much for the reply

@vxsx
Copy link
Contributor

vxsx commented Jan 16, 2018

I think we should definitely add something to the docs about it, thanks a lot!

vxsx added a commit to vxsx/djangocms-text-ckeditor that referenced this issue Jan 16, 2018
vxsx added a commit that referenced this issue Jan 16, 2018
Add note about __str__ of text enabled plugins (ref: #454)
@vxsx vxsx closed this as completed Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants