You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

Support is currently Offline

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

Please create a new Ticket and we will get back to you as soon as we can.

#102777 How to prevent JCE from stripping tags sometimes?

Posted in ‘Editor’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by mattsson on Friday, 31 January 2020 07:23 GMT

mattsson
Hello JCE Support,

I can't figure out why my JCE won't allow me to put break tags in my HTML sometimes. Sometimes I just want an extra blank line at the end of a Joomla article. For example, I have a table of data at the end of my article, followed by a closing </div>. Surely some setting in JCE Global Config or the default profile will solve my problem. Here's what I observe to be allowed and what isn't:

1) Between </table> and the closing </div>, exactly ONE <br/> tag is stripped. Two <br/> tags are preserved.

2) After the closing </div>, neither one nor two <br/> tags are preserved.

3) Within a paragraph, if I type <br/>, right after I type the closing angle bracket, JCE creates </br/>. What in the world is that? It's removed after I switch to the Editor tab and back and my one <br/> tag gets preserved in that case.

4) <p> </p> is preserved. But <p> and <br/> have different margins and padding associated with them. Why can't I have a single <br/> in the same place?

The stripping takes place when going from the Code tab to the Editor tab. I've already set Joomla to prevent stripping my article HTML by setting System Config > Text Filter Settings to allow Super Users (me) to have "No Filtering."

Even if I turn off "Validate HTML" in the JCE Global Config, the <br/> tags are stripped. And of course I prefer to have "Validate HTML" enabled in JCE.

I know you've answered this question a bunch of times, but none of the answers I've read today seem to solve my problem. Got any suggestions?

My Joomla version is 3.9.14 and JCE Pro version is 2.8.2. I think I've solved this problem in the past, but I checked three other Joomla websites, with about the same versions, and at all three websites, I see now JCE has trouble preserving my <br/> tags.

Sincerely, Carol Mattsson
Long time JCE subscriber.

Ryan
Long time JCE subscriber.
Thank you for your continued support! 😃 The single <br /> tag is used by browsers in editing mode to maintain structure within a block element, and create a position for the cursor to be placed. The editor tries to manage these, but generally considers single br tags at the beginning or end of a block element (p, div etc.) to be for this purpose, and either removes them, or replaces them with a space in the case of otherwise empty block elements. I plan to investigate whether this can be managed better, but this would require a lot of testing to ensure it does not affect other editor operations, but until then, I have made a few changes that would preserve single br tags that have an attribute of some kind (even if the values is empty), eg:

<br class="" />
You can test this in JCE Pro 2.8.4 RC6 - https://www.joomlacontenteditor.net/downloads/editor/pro/development Also, if your intention is to create a space between content areas by using a linebreak in this way, you should consider using a css margin or padding instead, as this would be easier to manage, and allow for the size of the space to be tweaked to suit the layout. Your template's css framework may already have an appropriate css class for this, otherwise something like the ones below might be useful, add to your template's css file:

.margin-bottom {
    margin-bottom: 10px
}

.margin-small-bottom {
    margin-bottom: 5px
}

.margin-top {
    margin-top: 10px
}

.margin-small-top {
    margin-top: 5px
}

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

mattsson
Hi Ryan,

Thanks for explaining. In my opinion, the BR tag lands in a page's HTML because I pasted in from MS Word or I specifically put it there in HTML editing mode. JCE has options to clean HTML pasted in from Word, but I see no reason to remove valid HTML5 BR tags otherwise. I'll try out your RC version to see if things improve, and I consider adding an empty class to my BR tag to be an acceptable compromise. Better would be a JCE setting that preserves BR tags independ from cleaning up MS Word HTML. Or quietly preserve BR tags encoded a certain way, e.g. if written like this: "<br />." (With a closing slash and one or more spaces before it.)

The reason I don't want to use CSS is a) then I need to add the class to whatever object I'm adjusting space for and b) make sure the class is in my style sheet. W3C already provides a BR tag, it's really annoying when JCE thinks it knows better. So you could say reason c) is bad attitude on user's part. Compounded by WordPress Classic editor stripping BR tags as well.

Sincerely,
Carol Mattsson

Ryan
Compounded by WordPress Classic editor stripping BR tags as well.


JCE and the Wordpress Classic Editor are both based on, or use Tinymce as the WYSIWYG editor "engine", but the same behaviour is present in Tinymce's direct competitor, CKEditor, so there must be a good reason for it.

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

Ryan
Ok, let us try an experiment.

Please download and install JCE Pro 2.8.4 RC7 - https://www.joomlacontenteditor.net/downloads/editor/pro/development

Then in the Editor Global Configuration, set a Custom Configuration Variable, with the Key as remove_trailing_brs and the Value as false.

https://cdn.joomlacontenteditor.net/tmp/102777-how-to-prevent-jce-from-stripping-tags-sometimes.jpg

This should now keep single <br /> tags, hopefully only remove some system ones, and not cause any unexpected behaviour.

Please report back if you notice anything ununusual related to this, especially in relation to cursor position in block elements (p, div etc.)

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

mattsson
Hi Ryan,

Before I could get to testing your RC, I made your custom configuration variable setting within JCE 2.8.5 - as provided by the Joomla updater at my demo site. Now my trailing BRs are SAVED! Thank you!

Before I set remove_trailing_brs to false, my trailing BRs disappeared, after going from Code tab, to Editor tab, and back.

For what it's worth, here is my test page: https://demo.elizahost.com/martis-home/jce-test, with BR tags added at the end.

I'm happy with this "secret" method of configuring JCE to behave the way I want. However I"m certainly OK to see the setting become more accessable (e.g. a checkbox in the global config somewhere). And I'm delighted to see the setting available in the released versions of JCE.

Thank you again Ryan.