public void TestBlank() { TextNode one = new TextNode("", ""); TextNode two = new TextNode(" ", ""); TextNode three = new TextNode(" \n\n ", ""); TextNode four = new TextNode("Hello", ""); TextNode five = new TextNode(" \nHello ", ""); Assert.IsTrue(one.IsBlank); Assert.IsTrue(two.IsBlank); Assert.IsTrue(three.IsBlank); Assert.IsFalse(four.IsBlank); Assert.IsFalse(five.IsBlank); }
internal void Insert(Token.Character characterToken) { Node node = new TextNode(characterToken.GetData(), baseUri); InsertNode(node); }
/// <summary> /// Create and prepend a new TextNode to this element. /// </summary> /// <param name="text">the unencoded text to add</param> /// <returns>this element</returns> public Element PrependText(string text) { TextNode node = new TextNode(text, BaseUri); PrependChild(node); return this; }
private static void AppendNormalisedText(StringBuilder accum, TextNode textNode) { string text = textNode.WholeText; if (PreserveWhitespace(textNode.Parent)) { accum.Append(text); } else { StringUtil.AppendNormalisedWhitespace(accum, text, TextNode.LastCharIsWhitespace(accum)); } }
internal void Insert(Token.Character characterToken) { Node node; // characters in script and style go in as datanodes, not text nodes string tagName = CurrentElement().TagName; if (tagName.Equals("script") || tagName.Equals("style")) { node = new DataNode(characterToken.GetData(), baseUri); } else { node = new TextNode(characterToken.GetData(), baseUri); } CurrentElement().AppendChild(node); }
public void Head(Node source, int depth) { if (source is Element) { Element sourceEl = (Element)source; if (this._enclosing.whitelist.IsSafeTag(sourceEl.TagName)) { // safe, clone and copy safe attrs Cleaner.ElementMeta meta = this._enclosing.CreateSafeElement(sourceEl); Element destChild = meta.el; this.destination.AppendChild(destChild); this.numDiscarded += meta.numAttribsDiscarded; this.destination = destChild; } else { if (source != this.root) { // not a safe tag, so don't add. don't count root against discarded. this.numDiscarded++; } } } else { if (source is TextNode) { TextNode sourceText = (TextNode)source; TextNode destText = new TextNode(sourceText.WholeText, source.BaseUri); this.destination.AppendChild(destText); } else { if (source is DataNode && this._enclosing.whitelist.IsSafeTag(source.Parent.NodeName)) { DataNode sourceData = (DataNode)source; DataNode destData = new DataNode(sourceData.WholeData, source.BaseUri); this.destination.AppendChild(destData); } else { // else, we don't care about comments, xml proc instructions, etc this.numDiscarded++; } } } }