Example #1
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);
            }
        }
Example #2
0
        /// <summary>
        /// Close out this element. This method will return true if something can be yielded; this this
        /// means it's got a parent at the top of the heirarchy. Otherwise it's just closed but false is
        /// returned.
        /// </summary>
        ///
        /// <param name="factory">
        /// The HTML factory to operate against.
        /// </param>
        ///
        /// <returns>
        /// An enumerator that allows foreach to be used to process close element in this collection.
        /// </returns>

        public IEnumerable <IDomObject> CloseElement(HtmlElementFactory factory)
        {
            IDomObject element = null;

            if (TryGetLiteral(factory, out element))
            {
                yield return(element);
            }

            if (Parent != null)
            {
                if (Parent.Parent == null)
                {
                    yield return(Parent.Element);
                }
                Parent.Reset(Pos);
                TokenizerState = TokenizerState.Finished;
            }
        }
Example #3
0
        /// <summary>
        /// Close out this element. This method will return true if something can be yielded; this this
        /// means it's got a parent at the top of the heirarchy. Otherwise it's just closed but false is
        /// returned.
        /// </summary>
        ///
        /// <param name="factory">
        /// The HTML factory to operate against.
        /// </param>
        ///
        /// <returns>
        /// An enumerator that allows foreach to be used to process close element in this collection.
        /// </returns>

        public IEnumerable<IDomObject> CloseElement(HtmlElementFactory factory)
        {
            IDomObject element = null;

            if (TryGetLiteral(factory, out element))
            {
                yield return element;
            }
                
            if (Parent != null)
            {
                if (Parent.Parent == null)
                {
                    yield return Parent.Element;
                } 
                Parent.Reset(Pos);
                TokenizerState = TokenizerState.Finished;
            }
        }
Example #4
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;
            }
        }