Can't handle br tag

Jun 1, 2010 at 7:56 AM
I try to use HTML Panel and it seems that br tags can't be rendered.
Nov 19, 2011 at 10:13 PM

Go into CssDefaults.cs and change:

html, address,
        blockquote, 
        body, dd, div,
        dl, dt, fieldset, form,
        frame, frameset,
        h1, h2, h3, h4,
        h5, h6, noframes,
        ol, p, ul, center,
        dir, hr, menu, pre   { display: block }

 

to:

html, address,
        blockquote, br,
        body, dd, div,
        dl, dt, fieldset, form,
        frame, frameset,
        h1, h2, h3, h4,
        h5, h6, noframes,
        ol, p, ul, center,
        dir, hr, menu, pre   { display: block }
Also, add the following at line 36 in HtmlTag.cs:
if (_tagName.EndsWith("/"))
{
   _tagName = _tagName.Substring(0, _tagName.Length - 1);
}
 
Aug 4, 2012 at 1:32 PM

Inserting the

if (_tagName.EndsWith("/"))
{
   _tagName = _tagName.Substring(0, _tagName.Length - 1);
}

code fails to take into account tags that have attributes. A better solution would be to change the

tag = tag.Substring(1, tag.Length - 2);

code a few lines above to

tag = tag.Substring(1, tag.Length - (tag.Length > 2 && tag[tag.Length - 2] == '/' ? 3 : 2));
Oct 10, 2012 at 6:20 PM
Edited Oct 10, 2012 at 6:23 PM

There is a further issue that I believe the code below remedies. Only the width of the last CssBox separated by '<br>' gets taken into account when figuring the overall width. CssBox.GetFullWidthWordsWith(CssBox b, ref float sum, ref float paddingsum) does the calculation but forgets the previous width when there are multiple CssBox children. The code below is an attempt to fix it that appears to work but has not been exhaustively tested. The modifications are the lines dealing with the introduced nullable float "oldSum".

private void GetFullWidthWordsWith(CssBox b, ref float sum, ref float paddingsum)
{
    float? oldSum = null;
    if (b.Display != CssConstants.Inline)
    {
        oldSum = sum;
        sum = 0;
    }
   
    paddingsum += b.ActualBorderLeftWidth + b.ActualBorderRightWidth + b.ActualPaddingRight
                  + b.ActualPaddingLeft;
  
    if (b.Words.Count > 0)
    {
        sum += b.Words.Sum(word => word.FullWidth);
    }
    else
    {
        foreach (CssBox bb in b.Boxes)
        {
            this.GetFullWidthWordsWith(bb, ref sum, ref paddingsum);
        }
    }
  
    if (oldSum.HasValue)
    {
        sum = Math.Max(sum, oldSum.Value);
    }
}
Developer
Nov 13, 2012 at 2:38 PM

fixed in 1.1.0.0