Пример #1
0
        private void OnEndTagClose(object sender, HtmlParserCloseTagEventArgs e)
        {
            if (_currentElementRecord != null)
            {
                ElementNode element = _currentElementRecord.Element;
                ReadOnlyCollection <ElementNode> children = ElementNode.EmptyCollection;
                if (_currentElementRecord.Children.Count > 0)
                {
                    children = new ReadOnlyCollection <ElementNode>(_currentElementRecord.Children);
                }

                ReadOnlyCollection <AttributeNode> startTagAttributes = AttributeNode.EmptyCollection;
                if (_currentElementRecord.StartTagAttributes.Count > 0)
                {
                    startTagAttributes = new ReadOnlyCollection <AttributeNode>(_currentElementRecord.StartTagAttributes);
                }

                ReadOnlyCollection <AttributeNode> endTagAttributes = AttributeNode.EmptyCollection;
                if (_currentElementRecord.EndTagAttributes.Count > 0)
                {
                    endTagAttributes = new ReadOnlyCollection <AttributeNode>(_currentElementRecord.EndTagAttributes);
                }

                element.EndTag.Complete(endTagAttributes, e.CloseAngleBracket, e.IsClosed, false, false);
                element.CompleteElement(e.CloseAngleBracket, true, children, startTagAttributes, endTagAttributes);

                _currentElementRecord = null;
            }

            CloseOrphanedEndTag(e.CloseAngleBracket, e.IsClosed);
        }
Пример #2
0
        void OnStartTagClose(object sender, HtmlParserCloseTagEventArgs e)
        {
            ITextProvider text = _parser.Text;

            Log.AppendFormat("OnStartTagClose: {0} ... {1} '{2}'\r\n\tIsClosed: {3}\r\n\tIsShortHand: {4}\r\n\r\n",
                             e.CloseAngleBracket.Start, e.CloseAngleBracket.End, text.GetText(e.CloseAngleBracket),
                             e.IsClosed, e.IsShorthand);
        }
Пример #3
0
        private void OnStartTagClose(object sender, HtmlParserCloseTagEventArgs e)
        {
            // e.Token contain Token with range for > or /> if well formed
            // or IsGhost is set to true otherwise

            Debug.Assert(_currentElementRecord != null);

            // Close start tag of the current element and push element
            // on the stack if element is not self-closing (or self-closed via />).

            ElementNode currentElement = _currentElementRecord.Element;
            ReadOnlyCollection <AttributeNode> attributes = AttributeNode.EmptyCollection;

            if (_currentElementRecord.StartTagAttributes.Count > 0)
            {
                attributes = new ReadOnlyCollection <AttributeNode>(_currentElementRecord.StartTagAttributes);
            }

            if (currentElement.StartTag.NameToken == null ||
                currentElement.Name.Equals("!doctype", StringComparison.OrdinalIgnoreCase))
            {
                currentElement.StartTag.Complete(attributes, e.CloseAngleBracket, e.IsClosed, e.IsShorthand, true);

                currentElement.CompleteElement(e.CloseAngleBracket, e.IsClosed,
                                               ElementNode.EmptyCollection,
                                               attributes,
                                               AttributeNode.EmptyCollection);
            }
            else
            {
                // Check if element is self-closing by calling URI info provider for a given namespace.
                bool selfClosing = false;

                NameToken nameToken = currentElement.StartTag.NameToken;
                if (nameToken != null)
                {
                    selfClosing = _tree.HtmlClosureProvider.IsSelfClosing(_tree.Text, nameToken.PrefixRange, nameToken.NameRange);
                }

                currentElement.StartTag.Complete(attributes, e.CloseAngleBracket, e.IsClosed, e.IsShorthand, selfClosing);

                currentElement.CompleteElement(e.CloseAngleBracket, e.IsClosed,
                                               ElementNode.EmptyCollection,
                                               attributes,
                                               AttributeNode.EmptyCollection);

                if (!selfClosing && !e.IsShorthand)
                {
                    _elementStack.Push(_currentElementRecord);
                }
            }

            _currentElementRecord = null;
        }