コード例 #1
0
            public void VisitExtension(HtmlElementIntermediateNode node)
            {
                // Disallow <script> in components as per #552
                if (string.Equals(node.TagName, "script", StringComparison.OrdinalIgnoreCase))
                {
                    for (var i = 0; i < node.Children.Count; i++)
                    {
                        // We allow you to suppress this error like:
                        // <script suppress-error="BL9992" />
                        var attribute = node.Children[i] as HtmlAttributeIntermediateNode;
                        if (attribute != null &&
                            attribute.AttributeName == "suppress-error" &&
                            attribute.Children.Count == 1 &&
                            attribute.Children[0] is HtmlAttributeValueIntermediateNode value &&
                            value.Children.Count == 1 &&
                            value.Children[0] is IntermediateToken token &&
                            token.IsHtml &&
                            string.Equals(token.Content, "BL9992", StringComparison.Ordinal))
                        {
                            node.Children.RemoveAt(i);
                            return;
                        }
                    }

                    var diagnostic = BlazorDiagnosticFactory.Create_DisallowedScriptTag(node.Source);
                    node.Diagnostics.Add(diagnostic);
                }

                base.VisitDefault(node);
            }