예제 #1
0
        public override IList <IHtmlValidationError> ValidateElement(ElementNode element)
        {
            var results    = new ValidationErrorCollection();
            var attributes = _global.Attributes.ToList();

            var match = HtmlCache.Elements.SingleOrDefault(e => e.Name.Equals(element.Name, StringComparison.OrdinalIgnoreCase));

            if (match != null && match.Attributes != null)
            {
                attributes.AddRange(match.Attributes);
            }

            foreach (HtmlAttribute htmlAttr in attributes)
            {
                var attrNode = element.GetAttribute(htmlAttr.Name);

                if (attrNode == null)
                {
                    continue;
                }

                int    index = element.GetAttributeIndex(attrNode.Name);
                string error;

                if (!IsTypeValid(attrNode.Value, htmlAttr, out error))
                {
                    results.AddAttributeError(element, error, HtmlValidationErrorLocation.AttributeValue, index);
                    Telemetry.TrackEvent("HTML: Attribute type invalid");
                }

                if (!IsRequireValid(htmlAttr, element, out error))
                {
                    results.AddAttributeError(element, error, HtmlValidationErrorLocation.AttributeName, index);
                    Telemetry.TrackEvent("HTML: Missing required attribute");
                }
            }

            return(results);
        }
예제 #2
0
        public override IList <IHtmlValidationError> ValidateElement(ElementNode element)
        {
            ValidationErrorCollection results    = new ValidationErrorCollection();
            List <HtmlAttribute>      attributes = _global.Attributes.ToList();

            HtmlElement match = HtmlElementsContainer.Elements.ExtendedSingleOrDefault($"Looking for tag {element.Name}", e => e.Name.Equals(element.Name, StringComparison.OrdinalIgnoreCase));

            if (match != null && match.Attributes != null)
            {
                attributes.AddRange(match.Attributes);
            }

            foreach (HtmlAttribute htmlAttr in attributes)
            {
                AttributeNode attrNode = element.GetAttribute(htmlAttr.Name);

                if (attrNode == null)
                {
                    continue;
                }

                int index = element.GetAttributeIndex(attrNode.Name);

                if (!IsTypeValid(attrNode.Value, htmlAttr, out string error))
                {
                    results.AddAttributeError(element, error, HtmlValidationErrorLocation.AttributeValue, index);
                }

                if (!IsRequireValid(htmlAttr, element, out error))
                {
                    results.AddAttributeError(element, error, HtmlValidationErrorLocation.AttributeName, index);
                }
            }

            return(results);
        }