예제 #1
0
 /// <summary>
 /// Constructs instance of HTML attribute
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="value">Value</param>
 /// <param name="type">Type</param>
 /// <param name="nameCoordinates">Coordinates of name</param>
 /// <param name="valueCoordinates">Coordinates of value</param>
 public HtmlAttribute(string name, string value, HtmlAttributeType type,
                      SourceCodeNodeCoordinates nameCoordinates, SourceCodeNodeCoordinates valueCoordinates)
 {
     Name             = name;
     Value            = value;
     Type             = type;
     NameCoordinates  = nameCoordinates;
     ValueCoordinates = valueCoordinates;
 }
예제 #2
0
        /// <summary>
        /// Constructs instance of HTML attribute
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="value">Value</param>
        /// <param name="type">Type</param>
        /// <param name="nameCoordinates">Coordinates of name</param>
        /// <param name="valueCoordinates">Coordinates of value</param>
        public HtmlAttribute(string name, string value, HtmlAttributeType type,
			SourceCodeNodeCoordinates nameCoordinates, SourceCodeNodeCoordinates valueCoordinates)
        {
            Name = name;
            Value = value;
            Type = type;
            NameCoordinates = nameCoordinates;
            ValueCoordinates = valueCoordinates;
        }
예제 #3
0
        public HtmlAttribute(string property, string value = null, HtmlAttributeType type = HtmlAttributeType.Equality, HtmlAttributeGroup group = HtmlAttributeGroup.Normal)
        {
            SetProperty(property);

            SetValue(value);

            SetAttributeType(type);

            SetAttributeGroup(group);
        }
        /// <summary>
        /// Gets a HTML attribute type
        /// </summary>
        /// <param name="tagNameInLowercase">Tag name in lowercase</param>
        /// <param name="tagFlags">Tag flags</param>
        /// <param name="attributeNameInLowercase">Attribute name in lowercase</param>
        /// <param name="attributes">List of attributes</param>
        /// <returns>Attribute type</returns>
        public HtmlAttributeType GetAttributeType(string tagNameInLowercase, HtmlTagFlags tagFlags,
                                                  string attributeNameInLowercase, List <HtmlAttribute> attributes)
        {
            HtmlAttributeType attributeType = HtmlAttributeType.Unknown;

            if (attributeNameInLowercase == "class")
            {
                attributeType = HtmlAttributeType.ClassName;
            }
            else if (attributeNameInLowercase == "style")
            {
                attributeType = HtmlAttributeType.Style;
            }
            else if (IsEventAttribute(attributeNameInLowercase))
            {
                attributeType = HtmlAttributeType.Event;
            }

            if (attributeType == HtmlAttributeType.Unknown && !tagFlags.IsSet(HtmlTagFlags.Xml))
            {
                if (IsBooleanAttribute(attributeNameInLowercase))
                {
                    attributeType = HtmlAttributeType.Boolean;
                }
                else if (IsNumericAttribute(tagNameInLowercase, attributeNameInLowercase))
                {
                    attributeType = HtmlAttributeType.Numeric;
                }
                else if (IsUriBasedAttribute(tagNameInLowercase, attributeNameInLowercase,
                                             attributes))
                {
                    attributeType = HtmlAttributeType.Uri;
                }
            }

            if (attributeType == HtmlAttributeType.Unknown)
            {
                attributeType = IsXmlBasedAttribute(attributeNameInLowercase) ?
                                HtmlAttributeType.Xml : HtmlAttributeType.Text;
            }

            return(attributeType);
        }
예제 #5
0
        private void BeforeAttributeValue()
        {
            while (true)
            {
                switch (Current())
                {
                case '\t':
                case '\r':
                case '\n':
                case '\f':
                case ' ':
                    Consume();
                    break;

                case '\'':
                    _attributeType = HtmlAttributeType.SingleQuoted;
                    Consume();
                    AttributeValue('\'');
                    return;

                case '"':
                    _attributeType = HtmlAttributeType.DoubleQuoted;
                    Consume();
                    AttributeValue('"');
                    return;

                case '>':
                    _attributeValueEnd = _attributeValueStart;
                    _attributeEnd      = Position();
                    Consume();
                    AddAttribute();
                    return;

                default:
                    _attributeType = HtmlAttributeType.Unquoted;
                    AttributeValueUnquoted();
                    return;
                }
            }
        }
예제 #6
0
        private void AttributeName(bool consumeOnce = false)
        {
            _attributeType       = HtmlAttributeType.NameOnly;
            _attributeNameStart  = _attributeNameEnd = _attributeStart = _attributeEnd = Position();
            _attributeValueStart = _attributeValueEnd = default;

            if (consumeOnce)
            {
                Consume();
            }

            while (true)
            {
                switch (Current())
                {
                case '\t':
                case '\r':
                case '\n':
                case '\f':
                case ' ':
                case '/':
                case '>':
                case '\0':
                    _attributeNameEnd = Position();
                    AfterAttributeName();
                    return;

                case '=':
                    _attributeNameEnd = Position();
                    Consume();
                    BeforeAttributeValue();
                    return;

                default:
                    Consume();
                    break;
                }
            }
        }
예제 #7
0
            protected void SaveTags(TagToRemoveType[] tags)
            {
                for (int tagIndex = 0; tagIndex < Tags.Count; tagIndex++)
                {
                    HtmlAttributeType[] attributes = new HtmlAttributeType[Tags[tagIndex].AttributeNames.Length];
                    //  Copies attributes.
                    for (int attributeIndex = 0; attributeIndex < attributes.Length; attributeIndex++)
                    {
                        attributes[attributeIndex] = new HtmlAttributeType()
                        {
                            Name = Tags[tagIndex].AttributeNames[attributeIndex]
                        };
                    }

                    tags[tagIndex] = new TagToRemoveType()
                    {
                        StartTagWithoutBracket = Tags[tagIndex].StartTag,
                        EndTag     = Tags[tagIndex].EndTag,
                        Attributes = attributes
                    };
                }
            }
예제 #8
0
 /// <summary>
 /// Constructs instance of HTML attribute
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="nameInLowercase">Name in lowercase</param>
 /// <param name="value">Value</param>
 /// <param name="type">Type</param>
 public HtmlAttribute(string name, string nameInLowercase, string value, HtmlAttributeType type)
     : this(name, nameInLowercase, value, type, SourceCodeNodeCoordinates.Empty, SourceCodeNodeCoordinates.Empty)
 {
 }
예제 #9
0
 internal HtmlAttribute(
     HtmlAttributeType type,
     ReadOnlyMemory <char> name,
     ReadOnlyMemory <char> value,
     ReadOnlyMemory <char> rawText,
     in HtmlTextRange range,
        /// <summary>
        /// Checks whether remove an the attribute, that has empty value
        /// </summary>
        /// <param name="tagName">Tag name</param>
        /// <param name="attributeName">Attribute name</param>
        /// <param name="attributeValue">Attribute value</param>
        /// <param name="attributeType">Attribute type</param>
        /// <returns>Result of check (true - can be removed; false - can not be removed)</returns>
        private static bool CanRemoveEmptyAttribute(string tagName, string attributeName, string attributeValue,
			HtmlAttributeType attributeType)
        {
            bool result = false;
            bool isZeroLengthString = (attributeValue.Length == 0);

            if (isZeroLengthString || string.IsNullOrWhiteSpace(attributeValue))
            {
                if (tagName == "input" && attributeName == "value")
                {
                    result = isZeroLengthString;
                }
                else if (attributeType == HtmlAttributeType.Event
                    || (tagName == "form" && attributeName == "action")
                    || _emptyAttributesForRemoval.Contains(attributeName))
                {
                    result = true;
                }
            }

            return result;
        }
예제 #11
0
 /// <summary>
 /// Constructs instance of HTML attribute
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="value">Value</param>
 /// <param name="type">Type</param>
 public HtmlAttribute(string name, string value, HtmlAttributeType type)
     : this(name, value, type, SourceCodeNodeCoordinates.Empty, SourceCodeNodeCoordinates.Empty)
 {
 }
예제 #12
0
        public HtmlAttribute SetAttributeType(HtmlAttributeType type)
        {
            Type = type;

            return(this);
        }