/// <summary> /// Returns a literal object for the text between HtmlStart (the last position of the end of a /// tag) and the current position. If !AllowLiterals then it's wrapped in a span. /// </summary> /// /// <param name="factory"> /// The HTML factory to operate against /// </param> /// <param name="literal"> /// [out] The literal. /// </param> /// /// <returns> /// true if it succeeds, false if it fails. /// </returns> public bool TryGetLiteral(HtmlElementFactory factory, out IDomObject literal) { if (Pos <= HtmlStart) { literal = null; return(false); } // There's plain text -return it as a literal. DomText lit; switch (InsertionMode) { case InsertionMode.Invalid: lit = new DomInvalidElement(); break; case InsertionMode.Text: InsertionMode = InsertionMode.Default; lit = new DomInnerText(); break; default: lit = new DomText(); break; } literal = lit; //if (factory.IsBound) //{ // lit.SetTextIndex(factory.Document, factory.Document.DocumentIndex.TokenizeString(HtmlStart, Pos - HtmlStart)); //} //else //{ string text = factory.Html.SubstringBetween(HtmlStart, Pos); literal.NodeValue = HtmlData.HtmlDecode(text); //} if (WrapLiterals) { DomElement wrapper = DomElement.Create("span"); wrapper.AppendChildUnsafe(literal); literal = wrapper; } if (Parent != null) { ((DomElement)Parent.Element).AppendChildUnsafe(literal); Reset(); return(false); } else { TokenizerState = TokenizerState.Finished; return(true); } }
protected override void WriteText(DomText text) { if (text == null) { return; } WriteText(text.Data); }
protected override void VisitText(DomText node) { if (node is HtmlText html) { VisitText(html); return; } _text.Append(node.Data); }
// The user clicked the Set Title button, so we'll take whatever text is in // the titleText NSTextField and replace the current content of the 'contentTitle' // H1 tag in the HTML with the new text. This shows you how to replace some HTML // content with new content. partial void setTitle(MonoMac.AppKit.NSButton sender) { var document = webView.MainFrame.DomDocument; DomText newText = document.CreateTextNode(titleText.StringValue); var contentTitle = document.GetElementById("contentTitle"); contentTitle.ReplaceChild(newText, contentTitle.FirstChild); }
/// <summary> /// Sets a child text for this element, using the text node type appropriate for this element's type /// </summary> /// /// <param name="el"> /// The element to add text to /// </param> /// <param name="text"> /// The text. /// </param> private void SetChildText(IDomElement el, string text) { if (el.ChildrenAllowed) { el.ChildNodes.Clear(); IDomText textEl = new DomText(text); el.ChildNodes.Add(textEl); } }
/// <summary> /// Returns a literal object for the text between HtmlStart (the last position of the end of a tag) and the current position. /// If !AllowLiterals then it's wrapped in a span. /// </summary> /// <param name="current"></param> /// <returns></returns> protected IDomObject GetLiteral(IterationData current) { // There's plain text -return it as a literal. IDomObject textObj; DomText lit; if (current.Invalid) { lit = new DomInvalidElement(); } else if (current.ReadTextOnly) { current.ReadTextOnly = false; lit = new DomInnerText(); } else { lit = new DomText(); } if (isBound) { lit.SetTextIndex(Document, Document.TokenizeString(current.HtmlStart, current.Pos - current.HtmlStart)); } else { string text = BaseHtml.SubstringBetween(current.HtmlStart, current.Pos); lit.NodeValue = Objects.HtmlDecode(text); } if (!current.AllowLiterals) { IDomElement wrapper = new DomElement("span"); wrapper.AppendChild(lit); textObj = wrapper; } else { textObj = lit; } if (current.Parent != null) { current.Parent.Element.AppendChild(textObj); current.Reset(); return(null); } else { current.Finished = true; return(textObj); } }
protected override void VisitText(DomText text) { string data; if (Utility.IsData(text)) { data = text.Data; } else { data = Utility.EscapeHtml(text.Data); } _sb.Write(data); }
/// <summary> /// Returns a literal object for the text between HtmlStart (the last position of the end of a /// tag) and the current position. If !AllowLiterals then it's wrapped in a span. /// </summary> /// /// <param name="factory"> /// The HTML factory to operate against /// </param> /// <param name="literal"> /// [out] The literal. /// </param> /// /// <returns> /// true if it succeeds, false if it fails. /// </returns> public bool TryGetLiteral(HtmlElementFactory factory, out IDomObject literal) { if (Pos <= HtmlStart) { literal = null; return false; } // There's plain text -return it as a literal. DomText lit; switch(InsertionMode) { case InsertionMode.Invalid: lit = new DomInvalidElement(); break; case InsertionMode.Text: InsertionMode =InsertionMode.Default; lit = new DomInnerText(); break; default: lit = new DomText(); break; } literal = lit; if (factory.IsBound) { lit.SetTextIndex(factory.Document, factory.Document.DocumentIndex.TokenizeString(HtmlStart, Pos - HtmlStart)); } else { string text = factory.Html.SubstringBetween(HtmlStart, Pos); literal.NodeValue = HtmlData.HtmlDecode(text); } if (WrapLiterals) { DomElement wrapper = DomElement.Create("span"); wrapper.ChildNodesInternal.AddAlways(literal); literal = wrapper; } if (Parent != null) { ((DomElement)Parent.Element).ChildNodesInternal.AddAlways(literal); Reset(); return false; } else { TokenizerState = TokenizerState.Finished; return true; } }
protected override void VisitText(DomText text) { _output.Append(text.Data); }
protected override void VisitText(DomText text) { if (text == null) throw new ArgumentNullException("text"); writer.WriteText(text.Data); }
protected override void VisitText(DomText node) { text.Append(node.Data); }
protected override void VisitText(DomText text) { string parent = stack.Peek(); CurrentOutput.WriteLine("{0}.AppendText(\"{1}\");", parent, CodeUtility.Escape(text.Data)); }
protected override void VisitText(DomText text) { if (text == null) throw new ArgumentNullException("text"); sb.Append(text.Data); }
/// <summary> /// Sets a child text for this element, using the text node type appropriate for this element's type /// </summary> /// /// <param name="el"> /// The element to add text to /// </param> /// <param name="text"> /// The text. /// </param> private void SetChildText(IDomElement el, string text) { if (el.ChildrenAllowed) { el.ChildNodes.Clear(); // Element types that cannot have HTML contents should not have the value encoded. // use DomInnerText node for those node types to preserve the raw text value //IDomText textEl = el.InnerHtmlAllowed ? // new DomText(text) : // new DomInnerText(text); IDomText textEl = new DomText(text); el.ChildNodes.Add(textEl); } }
public static bool IsData(DomText text) { DomElement e = text.ParentElement; return(e != null && (e.Name == "script" || e.Name == "style")); }
/// <summary> /// Returns a literal object for the text between HtmlStart (the last position of the end of a tag) and the current position. /// If !AllowLiterals then it's wrapped in a span. /// </summary> /// <param name="current"></param> /// <returns></returns> protected IDomObject GetLiteral(IterationData current) { // There's plain text -return it as a literal. IDomObject textObj; DomText lit; if (current.Invalid) { lit = new DomInvalidElement(); } else if (current.ReadTextOnly) { current.ReadTextOnly = false; lit = new DomInnerText(); } else { lit = new DomText(); } if (isBound) { lit.SetTextIndex(Document, Document.TokenizeString(current.HtmlStart, current.Pos - current.HtmlStart)); } else { string text = BaseHtml.SubstringBetween(current.HtmlStart, current.Pos); lit.NodeValue = Objects.HtmlDecode(text); } if (!current.AllowLiterals) { IDomElement wrapper = new DomElement("span"); wrapper.AppendChild(lit); textObj = wrapper; } else { textObj = lit; } if (current.Parent != null) { current.Parent.Element.AppendChild(textObj); current.Reset(); return null; } else { current.Finished = true; return textObj; } }
protected virtual void VisitText(DomText text) { if (text == null) throw new ArgumentNullException("text"); DefaultVisit(text); }
void IDomNodeVisitor.Visit(DomText text) { VisitText(text); }
protected override void VisitText(DomText text) { VisitDefaultTextCalledCount += 1; base.VisitText(text); }