Exemplo n.º 1
0
        private static Html.Node[] cleanNodes(Config c, Html.Node[] nodes)
        {
            if (c == null)
            {
                c = Config.DefaultConfig;
            }

            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = filterNode(c, nodes[i]);
                if (nodes[i].DataAtom == Html.Atom.Li)
                {
                    var wrapper = new Html.Node
                    {
                        Type     = Html.NodeType.Element,
                        Data     = "ul",
                        DataAtom = Html.Atom.Ul,
                    };
                    wrapper.AppendChild(nodes[i]);
                    nodes[i] = wrapper;
                }
            }

            if (c.WrapText)
            {
                nodes = wrapText(nodes);
            }

            return(nodes);
        }
Exemplo n.º 2
0
        private static void cleanChildren(Config c, Html.Node parent)
        {
            var children = new List <Html.Node>();

            while (parent.FirstChild != null)
            {
                var child = parent.FirstChild;
                parent.RemoveChild(child);
                children.Add(filterNode(c, child));
            }

            if (c.WrapText)
            {
                var ok = c.wrap.Contains(parent.DataAtom);
                if (!ok && parent.DataAtom == 0)
                {
                    ok = c.wrapCustom.Contains(parent.Data);
                }
                if (ok)
                {
                    var wrapped = wrapText(children.ToArray());
                    children.Clear();
                    children.AddRange(wrapped);
                }
            }

            foreach (var child in children)
            {
                parent.AppendChild(child);
            }
        }
Exemplo n.º 3
0
        private static Html.Node deepCopy(Html.Node n)
        {
            var clone = new Html.Node
            {
                Type      = n.Type,
                Attr      = n.Attr,
                Namespace = n.Namespace,
                Data      = n.Data,
                DataAtom  = n.DataAtom,
            };

            for (var c = n.FirstChild; c != null; c = c.NextSibling)
            {
                clone.AppendChild(deepCopy(c));
            }
            return(clone);
        }