This is a migrated thread and some comments may be shown as answers.

BR tags being trimmed when switching between modes

3 Answers 45 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Brian Ho
Top achievements
Rank 1
Brian Ho asked on 03 May 2011, 04:54 PM
Hi there,

I'm having a problem with <br /> tags being trimmed switching between design and html view.   I upgraded to the latest version (2011.1.413.35) and it's still happening.  Basically if I have html where the <br /> is inline with a <p> tag it will get trimmed off.  So If you start off by inputing this into the editor:

<p ><br /><br /><br /><br /><br />
Testing 1
2
3
</p>

Then if you switch to design mode and back you will get this:

<p ><br />
<br />
<br />
<br />
Testing 1
2
3
</p>

So one of the <br /> tags got trimmed off.  If you switch between views again you get this:
<p>
<br />
<br />
<br />
Testing 1
2
3
</p>

Now it will stop trimming the <br /> when you switch between modes since it's not inline with the <p> tag.  But if you manually move those 3 existing <br /> tags up to inline with the <p> tag it will continue to trim.  I tried turning off all content filters and it does the same thing.

Thanks for your help.

Brian

3 Answers, 1 is accepted

Sort by
0
Accepted
Stanimir
Telerik team
answered on 05 May 2011, 03:24 PM
Hi Brian Ho,

This is a result of the RemoveExtraBrakes content filter.
In order to avoid this problem you have two options:
1. Add content such as:
<p>
<br />
<br />
<br />
<br />
<br />
Testing 1
2
3
</p>

2. Add the following javascript code in the page where you are using the editor:
Telerik.Web.UI.Editor.RemoveExtraBrakes.prototype._performStripping = function(initContent)
{
    var newContent = initContent;
    if ($telerik.isFirefox || $telerik.isOpera) newContent = newContent.replace(/<BR\s?\/?>\s*<SCRIPT/ig, "<script"); //Problem in FF and Opera when the only content is a script
    newContent = newContent.replace(/<BR\s?\/?>\s*<\/(H1|H2|H3|H4|H5|H6|LI|P)/ig, function(match, group1, offset, fullText)
    {
        if (!fullText.substr(0, offset).match(/<BR\s?\/?>\s*$/gi))
        {
            match = "</" + group1;
        }
        return match;
    });
    //newContent = newContent.replace(/<(H1|H2|H3|H4|H5|H6|LI|P)([^>]*)?><BR\s?\/?>/ig, "<$1 $2>");
    if ($telerik.isSafari)
    {
        newContent = newContent.replace(/<p><\/p>/ig, "<p><br /></p>");
    }
    return newContent;
}
Note the commented row. It is the one that is causing the issue.


Regards,
Stanimir
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Brian Ho
Top achievements
Rank 1
answered on 06 May 2011, 09:23 PM
Thanks, your code snippet work.  Just a note, I'm not manually entering HTML in this manual but my users are doing content editing in design view and the resulting HTML is formatted this way.
0
Rowen
Top achievements
Rank 1
answered on 08 Aug 2011, 05:43 AM
Surely this is a bug in the RemoveExtraBrakes filter - when using shift-enter to enter a new line when newlinemode is set to paragraph, the br tag is added inline with the p tag - then when you switch views or save the line break disappears.

Seems to me that this behavior should be fixed since it is inconsistent and confusing.
Tags
Editor
Asked by
Brian Ho
Top achievements
Rank 1
Answers by
Stanimir
Telerik team
Brian Ho
Top achievements
Rank 1
Rowen
Top achievements
Rank 1
Share this question
or