Tidy.Core.Lexer.CanPrune C# (CSharp) Method

CanPrune() public method

public CanPrune ( Node element ) : bool
element Node
return bool
        public virtual bool CanPrune(Node element)
        {
            if (element.Type == Node.TEXT_NODE)
                return true;

            if (element.Content != null)
                return false;

            if (element.Tag == Options.TagTable.TagA && element.Attributes != null)
                return false;

            if (element.Tag == Options.TagTable.TagP && !Options.DropEmptyParas)
                return false;

            if (element.Tag == null)
                return false;

            if ((element.Tag.Model & ContentModel.ROW) != 0)
                return false;

            if (element.Tag == Options.TagTable.TagApplet)
                return false;

            if (element.Tag == Options.TagTable.TagObject)
                return false;

            if (element.Attributes != null &&
                (element.GetAttrByName("id") != null || element.GetAttrByName("name") != null))
                return false;

            return true;
        }

Usage Example

Beispiel #1
0
        public static void TrimEmptyElement(Lexer lexer, Node element)
        {
            TagCollection tt = lexer.Options.TagTable;

            if (lexer.CanPrune(element))
            {
                if (element.Type != TEXT_NODE)
                {
                    Report.Warning(lexer, element, null, Report.TRIM_EMPTY_ELEMENT);
                }

                DiscardElement(element);
            }
            else if (element.Tag == tt.TagP && element.Content == null)
            {
                /* replace <p></p> by <br><br> to preserve formatting */
                Node node = lexer.InferredTag("br");
                CoerceNode(lexer, element, tt.TagBr);
                InsertNodeAfterElement(element, node);
            }
        }