/// <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;
            }
        }
Example #2
0
        /// <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;
            }
        }