Ejemplo n.º 1
0
        private void FixElement(StringBuilder edit, MetadataControlResolver metadataControlResolver, ITextBuffer textBuffer, RwHtmlElementNode element)
        {
            // fix element name
            var metadata = metadataControlResolver.GetMetadata(element.FullTagName);
            if (metadata != null)
            {
                // we have found the metadata for the control
                if (metadata.FullTagName != element.FullTagName)
                {
                    // the used name differs from the correct, fix the tag name
                    edit.SetRange(element.TagPrefixToken.StartPosition, element.TagPrefixToken.Length, metadata.TagPrefix);
                    edit.SetRange(element.TagNameToken.StartPosition, element.TagNameToken.Length, metadata.TagName);

                    if (element.CorrespondingEndTag != null)
                    {
                        edit.SetRange(element.CorrespondingEndTag.TagPrefixToken.StartPosition, element.CorrespondingEndTag.TagPrefixToken.Length, metadata.TagPrefix);
                        edit.SetRange(element.CorrespondingEndTag.TagNameToken.StartPosition, element.CorrespondingEndTag.TagNameToken.Length, metadata.TagName);
                    }
                }

                // fix attribute names
                foreach (var attribute in element.Attributes)
                {
                    var property = metadata.GetProperty(attribute.AttributeName);
                    if (property != null && property.Name != attribute.AttributeName)
                    {
                        // the used name differs from the correct, fix the tag name
                        edit.SetRange(attribute.AttributeNameToken.StartPosition, attribute.AttributeNameToken.Length, property.Name);
                    }
                }

                // fix property elements
                foreach (var child in element.Content.OfType<RwHtmlElementNode>())
                {
                    var property = metadata.GetProperty(child.FullTagName);
                    if (property != null && property.IsElement && property.Name != child.FullTagName)
                    {
                        // the used name differs from the correct, fix the tag name
                        edit.SetRange(child.TagNameToken.StartPosition, child.TagNameToken.Length, property.Name);
                        if (child.CorrespondingEndTag != null)
                        {
                            edit.SetRange(child.CorrespondingEndTag.TagNameToken.StartPosition, child.CorrespondingEndTag.TagNameToken.Length, property.Name);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the element.
        /// </summary>
        private RwHtmlElementNode ReadElement()
        {
            var startIndex = CurrentIndex;
            var node = new RwHtmlElementNode() { StartPosition = Peek().StartPosition };

            Assert(RwHtmlTokenType.OpenTag);
            Read();
            SkipWhitespace();

            if (Peek().Type == RwHtmlTokenType.Slash)
            {
                Read();
                SkipWhitespace();
                node.IsClosingTag = true;
            }

            // element name
            Assert(RwHtmlTokenType.Text);
            node.TagNameToken = Read();
            node.TagName = node.TagNameToken.Text;
            if (Peek().Type == RwHtmlTokenType.Colon)
            {
                Read();

                node.TagPrefix = node.TagName;
                node.TagPrefixToken = node.TagNameToken;
                Assert(RwHtmlTokenType.Text);
                node.TagNameToken = Read();
                node.TagName = node.TagNameToken.Text;
            }
            SkipWhitespace();

            // attributes
            if (!node.IsClosingTag)
            {
                while (Peek().Type == RwHtmlTokenType.Text)
                {
                    var attribute = ReadAttribute();
                    attribute.ParentElement = node;
                    node.Attributes.Add(attribute);
                    SkipWhitespace();
                }

                if (Peek().Type == RwHtmlTokenType.Slash)
                {
                    Read();
                    SkipWhitespace();
                    node.IsSelfClosingTag = true;
                }
            }

            Assert(RwHtmlTokenType.CloseTag);
            Read();
            SkipWhitespace();

            node.Tokens.AddRange(GetTokensFrom(startIndex));
            return node;
        }