public override void VisitTagHelperBlock(TagHelperChunkGenerator chunkGenerator, Block block) { WriteBlock(block); if (block is TagHelperBlock tagHelperBlock) { // Write tag name WriteSeparator(); Write(tagHelperBlock.TagName); // Write descriptors foreach (var descriptor in tagHelperBlock.Binding?.Descriptors ?? Array.Empty <TagHelperDescriptor>()) { WriteSeparator(); // Get the type name without the namespace. var typeName = descriptor.Name.Substring(descriptor.Name.LastIndexOf('.') + 1); Write(typeName); } // Write tag mode, start tag and end tag Depth++; WriteNewLine(); WriteIndent(); Write(tagHelperBlock.TagMode); WriteSeparator(); Write(GetNodeContent(tagHelperBlock.SourceStartTag)); if (tagHelperBlock.SourceEndTag != null) { Write(" ... "); Write(GetNodeContent(tagHelperBlock.SourceEndTag)); } // Write attributes foreach (var attribute in tagHelperBlock.Attributes) { WriteNewLine(); WriteIndent(); Write(attribute.Name); WriteSeparator(); Write(attribute.AttributeStructure); if (attribute.Value != null) { Depth++; WriteNewLine(); // Recursively render attribute value VisitNode(attribute.Value); Depth--; } } Depth--; } }
/// <summary> /// Instantiates a new instance of the <see cref="TagHelperBlockBuilder"/> class /// with the provided values. /// </summary> /// <param name="tagName">An HTML tag name.</param> /// <param name="tagMode">HTML syntax of the element in the Razor source.</param> /// <param name="start">Starting location of the <see cref="TagHelperBlock"/>.</param> /// <param name="attributes">Attributes of the <see cref="TagHelperBlock"/>.</param> /// <param name="bindingResult"></param> public TagHelperBlockBuilder( string tagName, TagMode tagMode, SourceLocation start, IList <TagHelperAttributeNode> attributes, TagHelperBinding bindingResult) { TagName = tagName; TagMode = tagMode; Start = start; BindingResult = bindingResult; Attributes = new List <TagHelperAttributeNode>(attributes); Type = BlockKindInternal.Tag; ChunkGenerator = new TagHelperChunkGenerator(); }
// Internal for testing internal TagHelperBlockBuilder( string tagName, TagMode tagMode, IList <TagHelperAttributeNode> attributes, IEnumerable <SyntaxTreeNode> children) { TagName = tagName; TagMode = tagMode; Attributes = attributes; Type = BlockKindInternal.Tag; ChunkGenerator = new TagHelperChunkGenerator(); // Children is IList, no AddRange foreach (var child in children) { Children.Add(child); } }