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

ContentFilters=None not working as expected

1 Answer 94 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Warren
Top achievements
Rank 1
Warren asked on 08 May 2013, 09:09 PM
Hello,

Given this C# code:
        HtmlContentEditor1.Content = @"<html><body>
<img height=""0"" width=""0"">
<a href=""http://www.telerik.com"" style=""color: #9a9a9a;"">Telerik</a><br>
</body></html>";
and this in the .aspx file:
<telerik:RadEditor runat="server" ID="HtmlContentEditor1"
    EditModes="Html" Width="600" ContentFilters="None" />

we are seeing the HTML content get rewritten as:
<html><head></head><body>
<img width="0" height="0">
<a style="color: rgb(154, 154, 154);" href="http://www.telerik.com">Telerik</a><br>
</body></html>

and when the ContentFilters="None" property is removed altogether, the HTML content gets rewritten as:
<html>
    <head>
    </head>
    <body>
        <img alt="" width="0" height="0" />
        <a href="http://www.telerik.com" style="color: #9a9a9a;">Telerik</a><br />
    </body>
</html>

This is pretty unusual behaviour -- in the first case it reordered attributes and rewrote inline styles.... and in the second case it reordered attributes and added one in the <img> tag, but left the <a> tag alone.  

The HTML rewriting only seems to happen when initializing the control after setting the Content property. If I paste content into the HTML tab, then post the control back to the server, the content is unaltered.

We'd like to be able to use RadEditor for a project but it is critical that the editor not change the HTML content at all.  Is this possible?

I can provide a sample project but it's larger than the 2MB upload limit due to it including the controls DLL itself.  Controls version is 2013.1.319.40.

Any insight into this issue would be appreciated, thanks.

Warren.

1 Answer, 1 is accepted

Sort by
0
Joana
Telerik team
answered on 13 May 2013, 03:17 PM
Hello Warren,

The issue you have described is encountered because of browser behavior. ConvertXHTML filter handles this behavior and that's why you don't experience the issue when you remove ContentFilters="None" from your code. You can find more information about the Built-In content filters in this article.

I suggest that you use the following code that shows an example of creating a custom filter to replace the RGB value with HEX value.

<script>
    function OnClientLoad(editor, args) {
        var filter = new Filter();
        editor.get_filtersManager().add(filter);
        editor.set_html(filter.getHtmlContent(editor.get_html()));
    }
    Filter = function () {
        Filter.initializeBase(this);
        this.set_isDom(false);
        this.set_enabled(true);
        this.set_name("Filter");
        this.set_description("Color");
    }
    Filter.prototype =
        {
            getHtmlContent: function (content) {
                return this._removeHtmlTags(content);
            },
            _removeHtmlTags: function (initContent) {
                var cleanContent;
                cleanContent = initContent.replace(/rgb *\( *\d+ *, *\d+ *, *\d+ *\)/gi, function (match, offset, fullText) {
                    return Telerik.Web.UI.Editor.Utils._rgbToHex(match);
                });
                return cleanContent
            }
        }
    Filter.registerClass('Filter', Telerik.Web.UI.Editor.Filter);
 
</script>

I hope you find this information helpful.

Greetings,
Joana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Editor
Asked by
Warren
Top achievements
Rank 1
Answers by
Joana
Telerik team
Share this question
or