Exemple #1
0
        void SmartPop(Tag tag)
        {
            //"""We need to pop up to the previous tag of this type, unless
            //one of this tag's nesting reset triggers comes between this
            //tag and the previous tag of this type, OR unless this tag is a
            //generic nesting trigger and another generic nesting trigger
            //comes between this tag and the previous tag of this type.

            //Examples:
            // <p>Foo<b>Bar *<p>* should pop to 'p', not 'b'.
            // <p>Foo<table>Bar *<p>* should pop to 'table', not 'p'.
            // <p>Foo<table><tr>Bar *<p>* should pop to 'tr', not 'p'.

            // <li><ul><li> *<li>* should pop to 'ul', not the first 'li'.
            // <tr><table><tr> *<tr>* should pop to 'table', not the first 'tr'
            // <td><tr><td> *<td>* should pop to 'tr', not the first 'td'
            //"""

            IAllowsNestingSelf nestableTag = tag as IAllowsNestingSelf;
            Tag popTo = null;
            bool inclusive = true;
            foreach (Tag t in TagStack)
            {
                if (t.TagName == tag.TagName && nestableTag == null)
                {
                    popTo = tag;
                    break;
                }
                else if (nestableTag != null && nestableTag.NestingBreakers.Contains(t.GetType()) ||
                    (nestableTag == null && tag.ResetsNesting && t.ResetsNesting))
                {
                    popTo = t;
                    inclusive = false;
                    break;
                }
            }
            if (popTo != null)
            {
                PopToTag(popTo.TagName, inclusive);
            }
        }
Exemple #2
0
 void PushTag(Tag tag)
 {
     if (currentTag != null)
     {
         currentTag.AddChild(tag);
     }
     TagStack.Push(tag);
     currentTag = TagStack.Peek();
 }
Exemple #3
0
 void HandleStartEndTag(Tag tag)
 {
     HandleStartTag(tag);
     HandleEndTag(tag.TagName);
 }
Exemple #4
0
 void HandleStartTag(Tag tag)
 {
     if (quoteStack.Count > 0)
     {
         string attrs = string.Empty;
         foreach (var attrib in tag.Attributes)
         {
             attrs += string.Format(CultureInfo.InvariantCulture, " {0}=\"{1}\"", attrib.Name, attrib.Value);
         }
         HandleData(string.Format(CultureInfo.InvariantCulture, "<{0}{1}>", tag.TagName, attrs));
     }
     if (!tag.IsSelfClosing)
     {
         SmartPop(tag);
     }
     tag.Parent = currentTag;
     tag.Previous = Root.Previous;
     if (Root.Previous != null)
     {
         Root.Previous.Next = tag;
     }
     Root.Previous = tag;
     PushTag(tag);
     if (tag.IsSelfClosing)
     {
         PopTag();
     }
     if (quoteTags.ContainsKey(tag.TagName))
     {
         quoteStack.Push(tag.TagName);
     }
 }
Exemple #5
0
 public Parser()
 {
     interesting = interestingNormal;
     Root = Tag.Create("WBCore.DocumentObjectModelClasses.Root");
     PushTag(Root);
 }