private static void AppendWhitespaceIfBr(Element element, StringBuilder accum) { if (element.Tag.Name.Equals("br") && !TextNode.LastCharIsWhitespace(accum)) { accum.Append(" "); } }
private void AppendNormalisedText(StringBuilder accum, TextNode textNode) { String text = textNode.GetWholeText(); if (!PreserveWhitespace) { text = TextNode.NormaliseWhitespace(text); if (TextNode.LastCharIsWhitespace(accum)) { text = TextNode.StripLeadingWhitespace(text); } } accum.Append(text); }
/// <summary> /// </summary> /// <param name="accum"></param> private void Text(StringBuilder accum) { AppendWhitespaceIfBr(this, accum); foreach (Node child in ChildNodes) { if (child is TextNode) { TextNode textNode = (TextNode)child; AppendNormalisedText(accum, textNode); } else if (child is Element) { Element element = (Element)child; if (accum.Length > 0 && element.IsBlock && !TextNode.LastCharIsWhitespace(accum)) { accum.Append(" "); } element.Text(accum); } } }