private static void AddTag(ref HtmlTag head, ref HtmlTag current, Match tagMatch, string tagName)
        {
            var tag = new HtmlTag(tagName);

            string id = tagMatch.Groups["id"].Value;
            if (!string.IsNullOrWhiteSpace(id))
                tag.id(id.TrimStart('#'));

            tagMatch.Groups["class"]
                .Captures.Cast<Capture>().ToList()
                .ForEach(c => tag.addClass(c.Value.Trim('.')));

            tagMatch.Groups["attr"]
                .Captures.Cast<Capture>().ToList()
                .ForEach(c =>
                {
                    var attr = c.Value.Trim('[', ']');
                    var eqIndex = attr.IndexOf('=');
                    var name = attr.Substring(0, eqIndex);
                    var value = attr.Substring(eqIndex + 1, attr.Length - eqIndex - 1).Trim('\'');
                    tag.attr(name, value);
                });

            if (head == null)
            {
                current = tag;
                head = tag;
            }
            else
            {
                current.appendTag(tag);
                current = tag;
            }
        }
        private static void AddLiteal(HtmlTag head, HtmlTag current, string tagName)
        {
            if (head == null)
                throw new ArgumentException("cannot start with a literal");

            current.append(tagName.Trim('\''));
        }
 public HtmlTag appendTag(HtmlTag tag)
 {
     _children.Add(tag);
     return this;
 }
 public HtmlTag begin(string tagName)
 {
     var tag = new HtmlTag(tagName, this);
     appendTag(tag);
     return tag;
 }
 public HtmlTag(string name, HtmlTag parent)
 {
     _name = name;
     _parent = parent;
 }