Ejemplo n.º 1
0
        /// <summary>
        /// Applies the specified operation to the specified node. Return false if the node was removed or does not need any futher processing.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private bool ApplyNodeOperation(HtmlNode node, SanitizerOperation operation)
        {
            switch (operation)
            {
            case SanitizerOperation.FlattenTag:

                // Sanitize children, then insert them after this node and remove this node.
                // Do this in reverse to allow removal of nodes without hassle.
                for (int i = node.ChildNodes.Count - 1; i >= 0; i--)
                {
                    SanitizeNode(node.ChildNodes[i]);
                }

                foreach (var child in node.ChildNodes)
                {
                    node.ParentNode.InsertBefore(child, node);
                }
                node.Remove();
                return(false);

            case SanitizerOperation.RemoveTag:
                node.Remove();
                return(false);

            case SanitizerOperation.DoNothing:
                return(true);

            default:
                throw new InvalidOperationException("Unsupported sanitation operation.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies the specified operation to the specified node. Return false if the node was removed or does not need any futher processing.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private bool ApplyNodeOperation(HtmlNode node, SanitizerOperation operation)
        {
            switch (operation)
            {
            case SanitizerOperation.FlattenTag:

                // Sanitize children, then insert them after this node and remove this node.
                SanitizeChildren(node);
                foreach (var child in node.ChildNodes)
                {
                    node.ParentNode.InsertBefore(child, node);
                }
                node.Remove();
                return(false);

            case SanitizerOperation.RemoveTag:
                node.Remove();
                return(false);

            case SanitizerOperation.DoNothing:
                return(true);

            default:
                throw new InvalidOperationException("Unsupported sanitation operation.");
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Applies the specified global operation to a tag matching this rule.
 /// </summary>
 /// <param name="rule"></param>
 /// <param name="operation"></param>
 public static HtmlSanitizerTagRule Operation(this HtmlSanitizerTagRule rule, SanitizerOperation operation)
 {
     rule.Operation = operation;
     return(rule);
 }
Ejemplo n.º 4
0
 /// <summary>Specifies the operation to perform if this node does not have any attributes set.</summary>
 /// <param name="rule">The rule.</param>
 /// <param name="operation">The operation.</param>
 /// <returns></returns>
 public static HtmlSanitizerTagRule NoAttributes(this HtmlSanitizerTagRule rule, SanitizerOperation operation)
 {
     rule.NoAttributesOperation = operation;
     return(rule);
 }