Esempio n. 1
0
        public void Emit(Token token)
        {
            if (_isEmitPending)
            {
                throw new InvalidOperationException("There is an unread token pending!");
            }

            _emitPending   = token;
            _isEmitPending = true;

            if (token.Type == Token.TokenType.StartTag)
            {
                Token.StartTag startTag = (Token.StartTag)token;

                _lastStartTag = startTag;

                if (startTag.IsSelfClosing)
                {
                    _selfClosingFlagAcknowledged = false;
                }
            }
            else if (token.Type == Token.TokenType.EndTag)
            {
                Token.EndTag endTag = (Token.EndTag)token;

                if (endTag.Attributes != null)
                {
                    Error("Attributes incorrectly present on end tag");
                }
            }
        }
Esempio n. 2
0
        public void Emit(Token token)
        {
            if (_isEmitPending)
            {
                throw new InvalidOperationException("There is an unread token pending!");
            }

            _emitPending = token;
            _isEmitPending = true;

            if (token.Type == Token.TokenType.StartTag)
            {
                Token.StartTag startTag = (Token.StartTag)token;

                _lastStartTag = startTag;

                if (startTag.IsSelfClosing)
                {
                    _selfClosingFlagAcknowledged = false;
                }
            }
            else if (token.Type == Token.TokenType.EndTag)
            {
                Token.EndTag endTag = (Token.EndTag)token;

                if (endTag.Attributes != null)
                {
                    Error("Attributes incorrectly present on end tag");
                }
            }
        }
Esempio n. 3
0
        public Element InsertEmpty(Token.StartTag startTag)
        {
            Tag     tag = Tag.ValueOf(startTag.Name());
            Element el  = new Element(tag, _baseUri, startTag.Attributes);

            InsertNode(el);
            if (startTag.IsSelfClosing)
            {
                _tokeniser.AcknowledgeSelfClosingFlag();
                if (!tag.IsKnownTag()) // unknown tag, remember this is self closing for output
                {
                    tag.SetSelfClosing();
                }
            }
            return(el);
        }
Esempio n. 4
0
        public Element Insert(Token.StartTag startTag)
        {
            // handle empty unknown tags
            // when the spec expects an empty tag, will directly hit insertEmpty, so won't generate fake end tag.
            if (startTag.IsSelfClosing && !Tag.IsKnownTag(startTag.Name()))
            {
                Element el = InsertEmpty(startTag);
                Process(new Token.EndTag(el.TagName())); // ensure we get out of whatever state we are in
                return(el);
            }

            Element element = new Element(Tag.ValueOf(startTag.Name()), _baseUri, startTag.Attributes);

            Insert(element);
            return(element);
        }
Esempio n. 5
0
        Element Insert(Token.StartTag startTag)
        {
            Tag tag = Tag.ValueOf(startTag.Name());
            // todo: wonder if for xml parsing, should treat all tags as unknown? because it's not html.
            Element el = new Element(tag, _baseUri, startTag.Attributes);

            InsertNode(el);
            if (startTag.IsSelfClosing)
            {
                _tokeniser.AcknowledgeSelfClosingFlag();
                if (!tag.IsKnownTag()) // unknown tag, remember this is self closing for output. see above.
                {
                    tag.SetSelfClosing();
                }
            }
            else
            {
                _stack.AddLast(el);
            }
            return(el);
        }