protected override void OnEndTag(EndTag tag)
 {
     if (tag.NameEquals("head"))
     {
         _templateBuilder.Append("<style>");
         AppendBehaviorStyles();
         _templateBuilder.Append("</style>");
         AppendBehaviorObjectTag();
     }
     base.OnEndTag(tag);
 }
        protected override void OnEndTag(EndTag tag)
        {
            if (tag.NameEquals(HTMLTokens.Ul))
            {
                unorderedListLevel--;
            }
            else if (tag.NameEquals(HTMLTokens.Ol))
            {
                orderedListLevel--;
            }

            base.OnEndTag(tag);
        }
        private int ParseBeginTag(Match beginMatch, out Element element, out EndTag trailingEnd)
        {
            trailingEnd = null;

            Group tagNameGroup = beginMatch.Groups["tagname"];
            string tagName = tagNameGroup.Value;

            int tagPos = tagNameGroup.Index + tagNameGroup.Length;

            ArrayList attributes = null;
            LazySubstring extraResidue = null;
            bool isComplete = false;

            while (true)
            {
                Match match = endBeginTagMatcher.Match(tagPos);
                if (match != null)
                {
                    tagPos += match.Length;
                    if (match.Groups[1].Success)
                    {
                        isComplete = true;
                        if (supportTrailingEnd)
                            trailingEnd = new EndTag(data, tagPos, 0, tagName, true);
                    }
                    break;
                }

                match = attrNameMatcher.Match(tagPos);
                if (match == null)
                {
                    int residueStart = tagPos;
                    int residueEnd;

                    residueEnd = tagPos = data.IndexOfAny(new char[] { '<', '>' }, tagPos);
                    if (tagPos == -1)
                    {
                        residueEnd = tagPos = data.Length;
                    }
                    else if (data[tagPos] == '>')
                    {
                        tagPos++;
                    }
                    else
                    {
                        Debug.Assert(data[tagPos] == '<');
                    }

                    extraResidue = residueStart < residueEnd ? new LazySubstring(data, residueStart, residueEnd - residueStart) : null;
                    break;
                }
                else
                {
                    tagPos += match.Length;
                    LazySubstring attrName = new LazySubstring(data, match.Groups[1].Index, match.Groups[1].Length);
                    LazySubstring attrValue = null;
                    match = quotedAttrValueMatcher.Match(tagPos);
                    if (match != null)
                    {
                        attrValue = new LazySubstring(data, match.Groups[2].Index, match.Groups[2].Length);
                        tagPos += match.Length;
                    }
                    else
                    {
                        match = unquotedAttrValueMatcher.Match(tagPos);
                        if (match != null)
                        {
                            attrValue = new LazySubstring(data, match.Groups[1].Index, match.Groups[1].Length);
                            tagPos += match.Length;
                        }
                    }

                    // no attribute value; that's OK

                    if (attributes == null)
                        attributes = new ArrayList();
                    attributes.Add(new Attr(attrName, attrValue));
                }
            }

            int len = tagPos - beginMatch.Index;
            element = new BeginTag(data, beginMatch.Index, len, tagName, attributes == null ? null : (Attr[])attributes.ToArray(typeof(Attr)), isComplete, extraResidue);
            return len;
        }
        private int ParseMarkup(out Element element, out EndTag trailingEnd)
        {
            trailingEnd = null;

            Match m;

            // commentMatcher MUST be checked before directiveMatcher!
            m = commentMatcher.Match(pos);
            if (m != null)
            {
                element = new Comment(data, pos, m.Length);
                return m.Length;
            }

            // commentMatcher MUST be checked before directiveMatcher!
            m = directiveMatcher.Match(pos);
            if (m != null)
            {
                element = new MarkupDirective(data, pos, m.Length);
                return m.Length;
            }

            m = endMatcher.Match(pos);
            if (m != null)
            {
                element = new EndTag(data, pos, m.Length, m.Groups[1].Value);
                return m.Length;
            }

            m = beginMatcher.Match(pos);
            if (m != null)
            {
                return ParseBeginTag(m, out element, out trailingEnd);
            }

            element = null;
            return -1;
        }
        protected override void OnEndTag(EndTag tag)
        {
            if (tag.Implicit)
                return;
            if (tag.NameEquals(HTMLTokens.Title))
                _inTitle = false;

            if (TagsToPreserve.Contains(tag.Name.ToUpper(CultureInfo.InvariantCulture)))
                EmitTagAndAttributes(tag.Name, tag);
            else if (ReplaceTags.ContainsKey(tag.Name.ToUpper(CultureInfo.InvariantCulture)))
            {
                EmitTagAndAttributes((string)ReplaceTags[tag.Name.ToUpper(CultureInfo.InvariantCulture)], tag);
            }
        }
 protected override void OnEndTag(EndTag tag)
 {
     if (_collectingForTag != null)
     {
         if (tag.NameEquals(HTMLTokens.A))
         {
             if (_collectingForTagDepth == 0)
                 _collectingForTag = null;
             else
                 _collectingForTagDepth--;
         }
     }
     base.OnEndTag(tag);
 }
        private int ParseBeginTag(Match beginMatch, out Element element, out EndTag trailingEnd)
        {
            trailingEnd = null;

            Group  tagNameGroup = beginMatch.Groups["tagname"];
            string tagName      = tagNameGroup.Value;

            int tagPos = tagNameGroup.Index + tagNameGroup.Length;

            ArrayList     attributes   = null;
            LazySubstring extraResidue = null;
            bool          isComplete   = false;

            while (true)
            {
                Match match = endBeginTagMatcher.Match(tagPos);
                if (match != null)
                {
                    tagPos += match.Length;
                    if (match.Groups[1].Success)
                    {
                        isComplete = true;
                        if (supportTrailingEnd)
                        {
                            trailingEnd = new EndTag(data, tagPos, 0, tagName, true);
                        }
                    }
                    break;
                }

                match = attrNameMatcher.Match(tagPos);
                if (match == null)
                {
                    int residueStart = tagPos;
                    int residueEnd;

                    residueEnd = tagPos = data.IndexOfAny(new char[] { '<', '>' }, tagPos);
                    if (tagPos == -1)
                    {
                        residueEnd = tagPos = data.Length;
                    }
                    else if (data[tagPos] == '>')
                    {
                        tagPos++;
                    }
                    else
                    {
                        Debug.Assert(data[tagPos] == '<');
                    }

                    extraResidue = residueStart < residueEnd ? new LazySubstring(data, residueStart, residueEnd - residueStart) : null;
                    break;
                }
                else
                {
                    tagPos += match.Length;
                    LazySubstring attrName  = new LazySubstring(data, match.Groups[1].Index, match.Groups[1].Length);
                    LazySubstring attrValue = null;
                    match = quotedAttrValueMatcher.Match(tagPos);
                    if (match != null)
                    {
                        attrValue = new LazySubstring(data, match.Groups[2].Index, match.Groups[2].Length);
                        tagPos   += match.Length;
                    }
                    else
                    {
                        match = unquotedAttrValueMatcher.Match(tagPos);
                        if (match != null)
                        {
                            attrValue = new LazySubstring(data, match.Groups[1].Index, match.Groups[1].Length);
                            tagPos   += match.Length;
                        }
                    }

                    // no attribute value; that's OK

                    if (attributes == null)
                    {
                        attributes = new ArrayList();
                    }
                    attributes.Add(new Attr(attrName, attrValue));
                }
            }

            int len = tagPos - beginMatch.Index;

            element = new BeginTag(data, beginMatch.Index, len, tagName, attributes == null ? null : (Attr[])attributes.ToArray(typeof(Attr)), isComplete, extraResidue);
            return(len);
        }
        protected override void OnEndTag(EndTag tag)
        {

        }
 protected override void OnEndTag(EndTag tag)
 {
     if (suspendTagDepth > 0)
     {
         if (IsRegexMatch(IllegalTagTreeName, tag.Name))
             suspendTagDepth--;
     }
     else if (!IsRegexMatch(IllegalTagName, tag.Name))
     {
         try
         {
             PopEndTag(tag.Name);
             base.OnEndTag(tag);
         }
         catch (IllegalEndTagException)
         {
             //there is no corresponding open tag on the stack, so don't close this one.
             //This prevents an this HTML from messing up the HTML that surrounds it.
             if (FlagNotSet(Flag.RemoveUnopenedCloseTags))
                 base.OnEndTag(tag);
         }
     }
 }
 protected override void OnEndTag(EndTag tag)
 {
     if (preserveLinebreaksDepth > 0 && IsPreserveWhitespaceTag(tag.Name))
         preserveLinebreaksDepth++;
     base.OnEndTag(tag);
 }
        protected override void OnEndTag(EndTag tag)
        {
            if (tag == null)
                return;

            if (tag.NameEquals(HTMLTokens.Script))
            {
                if (!tag.Implicit)
                    if (_scriptDepth > 0)
                        _scriptDepth--;
                return;
            }

            if (tag.NameEquals(HTMLTokens.Head))
                EmitAdditionalMetaData();

            if (tag.NameEquals(HTMLTokens.Html) && _emittedTagsToClose.Contains(HTMLTokens.Body))
            {
                EmitCloseTag(HTMLTokens.Body);
                _emittedTagsToClose.Remove(HTMLTokens.Body);

            }

            Emit(tag.ToString());
            base.OnEndTag(tag);
        }
 protected virtual void OnEndTag(EndTag tag)
 {
     DefaultAction(tag);
 }