href of <a> anchor tags is getting stripped out

3 posts, 0 answers
  1. Byron
    Byron avatar
    3 posts
    Member since:
    Feb 2014

    Posted 19 Mar 2014 Link to this post

    The problem that I'm encountering is the xhtml that I'm passing in to the telerik RadRichTextBox is being modified by removing parts of the <a> anchor tag.  Specifically, the href and a custom property (not shown in my example).  I've include the xhtml that I send into the editor and what I get out from the editor.  The links in the editor do not work so I know that the link tag is being stripped when I set the xhtml to the document.

    Here is the Get/Set that I use.
    public string HtmlText
    {
                get
                {
                     string xhtml = new HtmlFormatProvider().Export(Document);
                     return xhtml;
                 }
                 set
                 {
                      Trace.WriteLine(xhtml);               
                      Document = new HtmlFormatProvider().Import(xhtml);
                      Trace.WriteLine(new HtmlFormatProvider().Export(Document));
                 }
    }


    xhmtl from the first Trace output (href="http://www.google.com" is there)
    <!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    </head>
    <body style="FONT-SIZE: 14pt; FONT-FAMILY: Terminal; COLOR: #000000; DIRECTION: ltr">
    <span style="FONT-SIZE: 14pt; FONT-FAMILY: Terminal"> </span>
    <p style="MARGIN-BOTTOM: 0px; DIRECTION: ltr; MARGIN-TOP: 0px">
    <a id="BC3BE1011F754A44B7BE22BA0208FB21" name="BC3BE1011F754A44B7BE22BA0208FB21" href="http://www.google.com" style="cursor:pointer;">test link to google</a>fdsa
    </p>
    <p style="MARGIN-BOTTOM: 0px; DIRECTION: ltr; MARGIN-TOP: 0px">
    &nbsp;
    </p>
    <p style="MARGIN-BOTTOM: 0px; DIRECTION: ltr; MARGIN-TOP: 0px">
    <a name="98E8EC0711AA4508BDAE5A97A4FDA86F" href="http://www.google.com" style="cursor:pointer;">test link to google</a>
    </p>
    <p style="MARGIN-BOTTOM: 0px; DIRECTION: ltr; MARGIN-TOP: 0px">
    &nbsp;
    </p>
    <p style="MARGIN-BOTTOM: 0px; DIRECTION: ltr; MARGIN-TOP: 0px">
    <a name="3C42D11201D24B7E8848383B02A7F119" href="http://www.google.com" style="cursor:pointer;">test link to google</a>
    </p>
    </body>
    </html>

    xhtml out of the editor, the href is missing

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled</title><style type="text/css">
    p { margin-top: 0px;margin-bottom: 0px;line-height: 1.15; }
    body { font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px; }
    .Normal { telerik-style-type: paragraph;telerik-style-name: Normal;border-collapse: collapse; }
    .TableNormal { telerik-style-type: table;telerik-style-name: TableNormal;border-collapse: collapse; }
    .NormalWeb { telerik-style-type: paragraph;telerik-style-name: NormalWeb;margin-top: 6.66px;margin-bottom: 6.66px;border-collapse: collapse; }
    .s_9397EFD2 { telerik-style-type: local;font-family: 'Arial';font-size: 18.6666666666667px;color: #000000; }
    .p_C499D8E6 { telerik-style-type: local;margin-top: 0px;margin-bottom: 0px; }
    .s_24B402CC { telerik-style-type: local;font-family: 'Arial';font-size: 18.6666666666667px;color: #0000FF; } </style></head><body><p class="NormalWeb "><span class="s_9397EFD2">&nbsp; </span></p><p class="NormalWeb p_C499D8E6"><a name="BC3BE1011F754A44B7BE22BA0208FB21"><span class="s_24B402CC">test link to google</span></a><span class="s_9397EFD2">fdsa </span></p><p class="NormalWeb p_C499D8E6"><span class="s_9397EFD2">&nbsp; </span></p><p class="NormalWeb p_C499D8E6"><a name="98E8EC0711AA4508BDAE5A97A4FDA86F"><span class="s_24B402CC">test link to google</span></a><span class="s_9397EFD2"> </span></p><p class="NormalWeb p_C499D8E6"><span class="s_9397EFD2">&nbsp; </span></p><p class="NormalWeb p_C499D8E6"><a name="3C42D11201D24B7E8848383B02A7F119"><span class="s_24B402CC">test link to google</span></a><span class="s_9397EFD2"> </span></p></body></html>
  2. Byron
    Byron avatar
    3 posts
    Member since:
    Feb 2014

    Posted 21 Mar 2014 Link to this post

    I found the problem.  I guess that Telerik only allows the href & target attributes in the <a> tag.  It is weird in that if the name attribute is in the <a> tag then all attributes (including href) are stripped out.  If the name attribute is not in the <a> tag but other attributes are, say id attribute, then the href attribute is left and only the non-allowed attributes are stripped out.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 24 Mar 2014 Link to this post

    Hello Byron,

     Our HtmlFormatProvider interprets the name attribute of <a> tag as bookmark and import it as such. In case the name attribute is missing it will look for href attribute and it will import it as hyperlink respecting the target attribute as well. This is expected behavior. 
    Please notice that custom attributes won't be respected at this point.

    If you have further questions feel free to contact us again.

    Regards,
    Mihail
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
Back to Top