Exemplo n.º 1
0
 public bool RemoveAttribute(string attrName, int startIndex)
 {
     Attr[] attributes = Attributes;
     for (int i = startIndex; i < attributes.Length; i++)
     {
         Attr attr = attributes[i];
         if (attr != null && attr.NameEquals(attrName))
         {
             attributes[i] = null;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        public Attr GetAttribute(string attrName, bool allowNoValue, int startIndex, out int foundAt)
        {
            foundAt = -1;

            if (attrName == null)
            {
                return(null);
            }

            Attr[] attributes = Attributes;
            for (int i = startIndex; i < attributes.Length; i++)
            {
                Attr attr = attributes[i];
                if (attr != null && attr.NameEquals(attrName) && (allowNoValue || attr.Value != null))
                {
                    foundAt = i;
                    return(attr);
                }
            }

            return(null);
        }
 protected abstract string OnMatchingAttr(BeginTag tag, Attr attr);
 protected abstract string OnMatchingAttr(BeginTag tag, Attr attr);
        /// <summary>
        /// Write a begin tag to the StringBuilder.  Attributes will be
        /// filtered according to the provided TagDesc, if any.
        /// </summary>
        private void WriteBeginTag(TagDesc desc, string tagName, Attr[] attributes, StringBuilder output)
        {
            output.Append("<" + tagName);
            for (int i = 0; i < attributes.Length; i++)
            {
                Attr attr = attributes[i];
                if (attr != null && (desc == null || desc.AttributeAllowed(attr.Name)))
                {
                    output.Append(" ");
                    output.Append(attributes[i].Name);
                    string val = attributes[i].Value;
                    if (val != null)
                    {
                        // hack for Word 2007 footnotes.
                        if (tagName == "a")
                        {
                            if (attributes[i].NameEquals("name"))
                            {
                                // Do a fast check before doing an expensive one
                                if (val.StartsWith("_ftn", StringComparison.OrdinalIgnoreCase) && Regex.IsMatch(val, @"^_ftn(ref)?(\d+)$", RegexOptions.IgnoreCase))
                                    val += WordFootnoteAnchorSuffix;
                            }
                            else if (attributes[i].NameEquals("href"))
                            {
                                // Do a fast check before doing an expensive one
                                if (val.StartsWith("#_ftn", StringComparison.OrdinalIgnoreCase) && Regex.IsMatch(val, @"^#_ftn(ref)?(\d+)$", RegexOptions.IgnoreCase))
                                    val += WordFootnoteAnchorSuffix;
                            }
                        }

                        output.Append("=\"" + HtmlUtils.EscapeEntities(val) + "\"");
                    }
                }
            }
            output.Append(">");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the first non-null attribute value whose name
        /// matches the given name (case insensitive).
        /// </summary>
        public string GetAttributeValue(string attrName)
        {
            Attr attr = GetAttribute(attrName);

            return((attr == null) ? null : attr.Value);
        }
Exemplo n.º 7
0
 internal BeginTag(string data, int offset, int len, string name, Attr[] attributes, bool complete, LazySubstring extraResidue) : base(data, offset, len, name)
 {
     this.complete = complete;
     _attributes = attributes == null ? new Attr[0] : attributes;
     this.extraResidue = extraResidue;
 }
Exemplo n.º 8
0
 public BeginTag(string data, int offset, int len, string name, Attr[] attributes, bool complete, string extraResidue) : this(data, offset, len, name, attributes, complete, LazySubstring.MaybeCreate(extraResidue))
 {
 }
        private bool IsIllegalAttribute(Attr attribute)
        {
            if (IsRegexMatch(IllegalAttribute, attribute.Name))
            {
                return true;
            }

            if (FlagIsSet(Flag.RemoveScriptAttributes))
            {
                switch (attribute.Name.ToUpperInvariant())
                {
                    // These are all the attributes from the HTML DTD that have %URI values.
                    case "SRC":
                    case "HREF":
                    case "DATASRC":
                    case "BACKGROUND":
                    case "LONGDESC":
                    case "USEMAP":
                    case "CLASSID":
                    case "CODEBASE":
                    case "DATA":
                    case "CITE":
                    case "ACTION":
                    case "PROFILE":
                        return IsScript(attribute.Value);
                }
            }
            return false;
        }
 private bool IsScriptAttribute(Attr attribute)
 {
     foreach (string jscriptAttribute in _jscriptAttributes)
         if (attribute.NameEquals(jscriptAttribute))
             return true;
     return false;
 }