private HtmlStringBuilder Append(HtmlElement element) { Append('<').Append(element.Name); foreach (var attribute in element.Attributes) { Append(' ').Append(attribute); } Append('>'); if (HtmlGrammar.IsVoidElement(element.Name) && !element.Children.Any()) { return(this); } _depth++; foreach (var child in element.Children) { AppendLine().Append(child); } _depth--; AppendLine().Append("</").Append(element.Name).Append('>'); return(this); }
private HtmlStringBuilder Append(HtmlText text) => HtmlGrammar.IsRawTextElement((text.Parent as HtmlElement)?.Name) ? Append(text.Value) : Append(WebUtility.HtmlEncode(text.Value));
private HtmlStringBuilder Append(HtmlText text) => HtmlGrammar.IsRawTextElement(_parentElements.Peek().Name) ? Append(text.Content) : Append(WebUtility.HtmlEncode(text.Content));