示例#1
0
        static void InlineElement(DomElement e)
        {
            StringWriter fore = new StringWriter();
            StringWriter aft  = new StringWriter();

            HxlElementTemplate.RenderElementStart(e, fore);
            HxlElementTemplate.RenderElementEnd(e, aft);
            HxlRenderWorkElement frag = (HxlRenderWorkElement)e.ChildNodes[0];
            List <string>        pre  = new List <string>();
            List <string>        post = new List <string>();

            pre.Add(CodeUtility.AppendDomText(fore.ToString()));
            pre.AddRange(frag.PreLines);
            post.AddRange(frag.PostLines);
            post.Add(CodeUtility.AppendDomText(aft.ToString()));
            var consolidated = new HxlRenderWorkElement(pre, post);

            frag.RemoveSelf();

            foreach (var m in frag.ChildNodes.ToArray())
            {
                consolidated.Append(m);
            }

            e.ReplaceWith(consolidated);
        }
        internal static HxlRenderWorkElement GetConsolidation(IEnumerable <DomNode> nodes,
                                                              IList <string> front,
                                                              IList <string> back,
                                                              HxlRenderWorkElement sentinel)
        {
            front = front ?? Empty <string> .List;
            back  = back ?? Empty <string> .List;

            // <render>
            //  <text /> <text /> <render /> <text/>
            // </render>
            // ==>
            // inline text with Write instructions and push up
            // nested render nodes
            List <string> pre     = new List <string>(front);
            List <string> post    = new List <string>();
            List <string> current = pre;

            foreach (var m in nodes)
            {
                if (m.NodeType == DomNodeType.Text)
                {
                    string sb = CodeUtility.AppendDomText(m.TextContent);
                    current.Add(sb);
                }
                else
                {
                    var hxlTextElement = m as HxlTextElement;
                    if (hxlTextElement != null)
                    {
                        string sb = CodeUtility.AppendDomText(hxlTextElement.Data);
                        current.Add(sb);
                    }
                    else if (m.NodeType == DomNodeType.Element)
                    {
                        HxlRenderWorkElement mr = (HxlRenderWorkElement)m;
                        current.AddRange(mr.PreLines);

                        // If the element has children, then there can be only
                        // one
                        if (m.ChildNodes.Count > 0)
                        {
                            current = post;
                        }

                        current.AddRange(mr.PostLines);
                    }
                }
            }

            post.AddRange(back);
            var result = new HxlRenderWorkElement(pre, post);

            if (sentinel != null)
            {
                sentinel.RemoveSelf();

                foreach (var m in sentinel.ChildNodes.ToArray())
                {
                    result.Append(m);
                }
            }
            return(result);
        }