Skip to content

Commit 468096f

Browse files
authored
Merge pull request #76 from MuhKuh7/blank_line_fix
Fixed line break handling (#52)
2 parents 785c8da + 81d021f commit 468096f

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

external/HtmlRenderer/Core/Parse/DomParser.cs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -648,42 +648,31 @@ private static void CorrectImgBoxes(CssBox box)
648648
/// move to a new line</param>
649649
private static void CorrectLineBreaksBlocks(CssBox box, ref bool followingBlock)
650650
{
651-
followingBlock = followingBlock || box.IsBlock;
652651
foreach (var childBox in box.Boxes)
653652
{
654653
CorrectLineBreaksBlocks(childBox, ref followingBlock);
655-
followingBlock = childBox.Words.Count == 0 && (followingBlock || childBox.IsBlock);
656-
}
657654

658-
int lastBr = -1;
659-
CssBox brBox;
660-
do
661-
{
662-
brBox = null;
663-
for (int i = 0; i < box.Boxes.Count && brBox == null; i++)
655+
if (childBox.IsBrElement)
664656
{
665-
if (i > lastBr && box.Boxes[i].IsBrElement)
666-
{
667-
brBox = box.Boxes[i];
668-
lastBr = i;
669-
}
670-
else if (box.Boxes[i].Words.Count > 0)
671-
{
672-
followingBlock = false;
673-
}
674-
else if (box.Boxes[i].IsBlock)
657+
childBox.Display = CssConstants.Block;
658+
659+
if (followingBlock)
675660
{
676-
followingBlock = true;
661+
childBox.Height = ".95em"; // TODO:a check the height to min-height when it is supported
677662
}
678-
}
679663

680-
if (brBox != null)
664+
// after <br>, treat as if we just had a block so consecutive <br> will also create empty lines
665+
followingBlock = true;
666+
}
667+
else if (childBox.Words.Count > 0)
681668
{
682-
brBox.Display = CssConstants.Block;
683-
if (followingBlock)
684-
brBox.Height = ".95em"; // TODO:a check the height to min-height when it is supported
669+
followingBlock = false;
685670
}
686-
} while (brBox != null);
671+
else if (childBox.IsBlock)
672+
{
673+
followingBlock = true;
674+
}
675+
}
687676
}
688677

689678
/// <summary>

0 commit comments

Comments
 (0)