private void ValidateParentAllowsPlainStartTag(MarkupStartTagSyntax tagBlock) { var tagName = tagBlock.GetTagNameWithOptionalBang(); // Treat partial tags such as '</' which have no tag names as content. if (string.IsNullOrEmpty(tagName)) { var firstChild = tagBlock.Children.First(); Debug.Assert(firstChild is MarkupTextLiteralSyntax); ValidateParentAllowsContent(firstChild); return; } if (!HasAllowedChildren()) { return; } var tagHelperBinding = _tagHelperBinder.GetBinding( tagName, attributes: Array.Empty <KeyValuePair <string, string> >(), parentTagName: CurrentParentTagName, parentIsTagHelper: CurrentParentIsTagHelper); // If we found a binding for the current tag, then it is a tag helper. Use the prefixed allowed children to compare. var allowedChildren = tagHelperBinding != null ? CurrentTagHelperTracker.PrefixedAllowedChildren : CurrentTagHelperTracker.AllowedChildren; if (!allowedChildren.Contains(tagName, StringComparer.OrdinalIgnoreCase)) { OnAllowedChildrenStartTagError(CurrentTagHelperTracker, tagName, tagBlock, _errorSink, _source); } }
private bool TryRewriteTagHelperStart( MarkupStartTagSyntax startTag, MarkupEndTagSyntax endTag, out MarkupTagHelperStartTagSyntax rewritten, out TagHelperInfo tagHelperInfo) { rewritten = null; tagHelperInfo = null; // Get tag name of the current block var tagName = startTag.GetTagNameWithOptionalBang(); // Could not determine tag name, it can't be a TagHelper, continue on and track the element. if (string.IsNullOrEmpty(tagName) || tagName.StartsWith("!", StringComparison.Ordinal)) { return(false); } TagHelperBinding tagHelperBinding; if (!IsPotentialTagHelperStart(tagName, startTag)) { return(false); } var tracker = CurrentTagHelperTracker; var tagNameScope = tracker?.TagName ?? string.Empty; // We're now in a start tag block, we first need to see if the tag block is a tag helper. var elementAttributes = GetAttributeNameValuePairs(startTag); tagHelperBinding = _tagHelperBinder.GetBinding( tagName, elementAttributes, CurrentParentTagName, CurrentParentIsTagHelper); // If there aren't any TagHelperDescriptors registered then we aren't a TagHelper if (tagHelperBinding == null) { // If the current tag matches the current TagHelper scope it means the parent TagHelper matched // all the required attributes but the current one did not; therefore, we need to increment the // OpenMatchingTags counter for current the TagHelperBlock so we don't end it too early. // ex: <myth req="..."><myth></myth></myth> We don't want the first myth to close on the inside // tag. if (string.Equals(tagNameScope, tagName, StringComparison.OrdinalIgnoreCase)) { tracker.OpenMatchingTags++; } return(false); } ValidateParentAllowsTagHelper(tagName, startTag); ValidateBinding(tagHelperBinding, tagName, startTag); // We're in a start TagHelper block. ValidateStartTagSyntax(tagName, startTag); var rewrittenStartTag = TagHelperBlockRewriter.Rewrite( tagName, _featureFlags, startTag, tagHelperBinding, _errorSink, _source); var tagMode = TagHelperBlockRewriter.GetTagMode(startTag, endTag, tagHelperBinding); tagHelperInfo = new TagHelperInfo(tagName, tagMode, tagHelperBinding); rewritten = rewrittenStartTag; return(true); }