コード例 #1
0
        public override string Serialize(HtmlSerializeType serializeType, int depth)
        {
            var doctype = Doctype ?? "";

            if (serializeType == HtmlSerializeType.PrettyPrint)
            {
                doctype += "\r";
            }
            return(doctype + base.Serialize(serializeType, depth));
        }
コード例 #2
0
        public virtual string Serialize(HtmlSerializeType serializeType, int depth)
        {
            var openingTag = SerializeOpenTag();

            if (serializeType == HtmlSerializeType.PrettyPrint)
            {
                if ((string.IsNullOrEmpty(InnerText) && Children.Count > 0) || IsVoid)
                {
                    openingTag += "\r";
                }
            }

            if (IsVoid)
            {
                return(openingTag);
            }

            var closingTag = "</" + ElementTag + ">";

            if (depth > MaximumIndentDepth)
            {
                depth      = MaximumIndentDepth;
                closingTag = "\t" + closingTag;
            }

            var shouldIndent = depth >= MinimumIndentDepth && depth <= MaximumIndentDepth;

            if (shouldIndent)
            {
                for (var counter = 0; counter < depth - 1; counter++)
                {
                    closingTag = "\t" + closingTag;
                }
            }

            var innerText = InnerText ?? "";

            foreach (var child in Children)
            {
                if (shouldIndent)
                {
                    for (var counter = 0; counter < depth; counter++)
                    {
                        innerText += "\t";
                    }
                }
                if (!string.IsNullOrWhiteSpace(child.InnerText) && child.Children.Count == 0)
                {
                    innerText += child.Serialize(serializeType, 0);
                }
                else
                {
                    innerText += child.Serialize(serializeType, depth + 1);
                }
            }

            var html = openingTag + innerText + closingTag;

            if (serializeType == HtmlSerializeType.PrettyPrint)
            {
                html += "\r";
            }
            return(html);
        }
コード例 #3
0
 public string Serialize(HtmlSerializeType serializeType) => Serialize(serializeType, 0);