private void WriteTagMatchingRule(JsonWriter writer, TagMatchingRuleDescriptor ruleDescriptor, JsonSerializer serializer) { writer.WriteStartObject(); writer.WritePropertyName(nameof(TagMatchingRuleDescriptor.TagName)); writer.WriteValue(ruleDescriptor.TagName); writer.WritePropertyName(nameof(TagMatchingRuleDescriptor.ParentTag)); writer.WriteValue(ruleDescriptor.ParentTag); writer.WritePropertyName(nameof(TagMatchingRuleDescriptor.TagStructure)); writer.WriteValue(ruleDescriptor.TagStructure); writer.WritePropertyName(nameof(TagMatchingRuleDescriptor.Attributes)); writer.WriteStartArray(); foreach (var requiredAttribute in ruleDescriptor.Attributes) { WriteRequiredAttribute(writer, requiredAttribute, serializer); } writer.WriteEndArray(); writer.WritePropertyName(nameof(TagMatchingRuleDescriptor.Diagnostics)); serializer.Serialize(writer, ruleDescriptor.Diagnostics); writer.WriteEndObject(); }
public static bool SatisfiesRule( StringSegment tagNameWithoutPrefix, StringSegment parentTagNameWithoutPrefix, IReadOnlyList <KeyValuePair <string, string> > tagAttributes, TagMatchingRuleDescriptor rule) { var satisfiesTagName = SatisfiesTagName(tagNameWithoutPrefix, rule); if (!satisfiesTagName) { return(false); } var satisfiesParentTag = SatisfiesParentTag(parentTagNameWithoutPrefix, rule); if (!satisfiesParentTag) { return(false); } var satisfiesAttributes = SatisfiesAttributes(tagAttributes, rule); if (!satisfiesAttributes) { return(false); } return(true); }
public static bool SatisfiesParentTag(StringSegment parentTagNameWithoutPrefix, TagMatchingRuleDescriptor rule) { if (rule.ParentTag != null && !parentTagNameWithoutPrefix.Equals(rule.ParentTag, rule.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)) { return(false); } return(true); }
private static bool Predicate(TagMatchingRuleDescriptor rule, string helper, IEnumerable <string> arguments) { // Does it match the required tag name if (rule.TagName != "*" && !String.Equals(rule.TagName, helper, StringComparison.OrdinalIgnoreCase)) { return(false); } // Does it expect any specific attribute? if (!rule.Attributes.Any()) { return(true); } // Are all required attributes present? var allRequired = rule.Attributes.All(attr => arguments.Any(name => { // Exact match if (String.Equals(name, attr.Name, StringComparison.OrdinalIgnoreCase)) { return(true); } // Check by replacing all '_' with '-', e.g. asp_src will map to asp-src name = name.Replace('_', '-'); if (String.Equals(name, attr.Name, StringComparison.OrdinalIgnoreCase)) { return(true); } if (attr.Name.StartsWith(AspPrefix, StringComparison.Ordinal)) { if (name.AsSpan().Equals(attr.Name.AsSpan(AspPrefix.Length), StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); })); if (allRequired) { return(true); } return(false); }
public static bool SatisfiesTagName(StringSegment tagNameWithoutPrefix, TagMatchingRuleDescriptor rule) { if (StringSegment.IsNullOrEmpty(tagNameWithoutPrefix)) { return(false); } if (tagNameWithoutPrefix[0] == ElementOptOutCharacter) { // TagHelpers can never satisfy tag names that are prefixed with the opt-out character. return(false); } if (rule.TagName != ElementCatchAllName && rule.TagName != null && !tagNameWithoutPrefix.Equals(rule.TagName, rule.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)) { return(false); } return(true); }
public static bool SatisfiesAttributes(IReadOnlyList <KeyValuePair <string, string> > tagAttributes, TagMatchingRuleDescriptor rule) { if (!rule.Attributes.All(