Ejemplo n.º 1
0
        void BuildTagTree()
        {
            //handle <br/> and attributes
            RootTag = null;
            Stack<Tag> tags = new Stack<Tag>() ;

            for (int i = 0; i < tokens.Length; )
            {
                if (tokens[i] == "<")
                {
                    for (i++; tokens[i].Trim().Length == 0; i++) ;   // Skip whitespaces till name of tag
                    Tag tag = new Tag(tokens[i]);
                    if (tags.Count > 0)
                        tags.Peek().Content.Add(tag);

                    List<string> NonParsedAttributes = new List<string>();
                    for (i++; tokens[i] != ">" && tokens[i] != "/>"; i++)
                        NonParsedAttributes.Add(tokens[i]);
                    tag.Attributes = TagAttribute.ParseAttributes(NonParsedAttributes);

                    if (tokens[i] == ">")
                    {
                        tags.Push(tag);
                        if (RootTag == null)
                            RootTag = tag;
                    }
                    i++;
                }
                else if (tokens[i] == "</")
                {
                    while (tokens[i++] != ">") ;    // Skip all till closing the tag
                    tags.Pop();
                }
                else
                {
                    if (tokens[i].Trim().Length > 0)    // Add only non-whitespace text
                        tags.Peek().Content.Add(new Text(tokens[i]));
                    i++;
                }
            }
        }
Ejemplo n.º 2
0
 private void PrintTagTree(Tag tag,int depth)
 {
     foreach (Token token in tag.Content)
         if (token is CodeRenderer.MarkupStructure.Text)
             token.Print(depth);
         else
         {
             token.Print(depth);
             foreach (TagAttribute attribute in ((Tag)token).Attributes)
                 attribute.Print(depth);
             PrintTagTree((Tag)token, depth + 1);
         }
     return;
 }