BR tags being trimmed when switching between modes

4 posts, 1 answers
  1. Brian Ho
    Brian Ho avatar
    12 posts
    Member since:
    Mar 2010

    Posted 03 May 2011 Link to this post

    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
  2. Answer
    Stanimir
    Admin
    Stanimir avatar
    1653 posts

    Posted 05 May 2011 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brian Ho
    Brian Ho avatar
    12 posts
    Member since:
    Mar 2010

    Posted 06 May 2011 Link to this post

    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.
  5. Rowen
    Rowen avatar
    13 posts
    Member since:
    Aug 2008

    Posted 08 Aug 2011 Link to this post

    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.
Back to Top