public override void VisitMarkupTagHelperAttributeValue(MarkupTagHelperAttributeValueSyntax node) { // We don't generate a classified span when the attribute value is a simple literal value. // This is done so we maintain the classified spans generated in 2.x which // used ConditionalAttributeCollapser (combines markup literal attribute values into one span with no block parent). if (node.Children.Count > 1 || (node.Children.Count == 1 && node.Children[0] is MarkupDynamicAttributeValueSyntax)) { WriteBlock(node, BlockKindInternal.Markup, base.VisitMarkupTagHelperAttributeValue); return; } base.VisitMarkupTagHelperAttributeValue(node); }
public override void VisitMarkupTagHelperAttributeValue(MarkupTagHelperAttributeValueSyntax node) { foreach (var child in node.Children) { if (child.Kind == SyntaxKind.MarkupTextLiteral) { AddSemanticRange(child, RazorSemanticTokensLegend.MarkupAttributeQuote); } else { Visit(child); } } }
public override void VisitMarkupTagHelperAttributeValue(MarkupTagHelperAttributeValueSyntax node) { WriteBlock(node, FormattingBlockKind.Markup, base.VisitMarkupTagHelperAttributeValue); }
private static MarkupTagHelperDirectiveAttributeSyntax RewriteToDirectiveAttribute( MarkupAttributeBlockSyntax attributeBlock, TryParseResult result, MarkupTagHelperAttributeValueSyntax rewrittenValue) { // // Consider, <Foo @bind:param="..." /> // We're now going to rewrite @bind:param from a regular MarkupAttributeBlock to a MarkupTagHelperDirectiveAttribute. // We need to split the name "@bind:param" into four parts, // @ - Transition (MetaCode) // bind - Name (Text) // : - Colon (MetaCode) // param - ParameterName (Text) // var attributeName = result.AttributeName; var attributeNameSyntax = attributeBlock.Name; var transition = SyntaxFactory.RazorMetaCode( new SyntaxList <SyntaxToken>(SyntaxFactory.MissingToken(SyntaxKind.Transition))); RazorMetaCodeSyntax colon = null; MarkupTextLiteralSyntax parameterName = null; if (attributeName.StartsWith("@", StringComparison.Ordinal)) { attributeName = attributeName.Substring(1); var attributeNameToken = SyntaxFactory.Token(SyntaxKind.Text, attributeName); attributeNameSyntax = SyntaxFactory.MarkupTextLiteral().AddLiteralTokens(attributeNameToken); var transitionToken = SyntaxFactory.Token(SyntaxKind.Transition, "@"); transition = SyntaxFactory.RazorMetaCode(new SyntaxList <SyntaxToken>(transitionToken)); } if (attributeName.IndexOf(':') != -1) { var segments = attributeName.Split(new[] { ':' }, 2); var attributeNameToken = SyntaxFactory.Token(SyntaxKind.Text, segments[0]); attributeNameSyntax = SyntaxFactory.MarkupTextLiteral().AddLiteralTokens(attributeNameToken); var colonToken = SyntaxFactory.Token(SyntaxKind.Colon, ":"); colon = SyntaxFactory.RazorMetaCode(new SyntaxList <SyntaxToken>(colonToken)); var parameterNameToken = SyntaxFactory.Token(SyntaxKind.Text, segments[1]); parameterName = SyntaxFactory.MarkupTextLiteral().AddLiteralTokens(parameterNameToken); } var rewritten = SyntaxFactory.MarkupTagHelperDirectiveAttribute( attributeBlock.NamePrefix, transition, attributeNameSyntax, colon, parameterName, attributeBlock.NameSuffix, attributeBlock.EqualsToken, attributeBlock.ValuePrefix, rewrittenValue, attributeBlock.ValueSuffix); rewritten = rewritten.WithTagHelperAttributeInfo( new TagHelperAttributeInfo(result.AttributeName, parameterName?.GetContent(), result.AttributeStructure, result.IsBoundAttribute, isDirectiveAttribute: true)); return(rewritten); }