/// <summary>Generate the html text for this tree of elements in 'sb'. Set 'indent' to -1 for no indenting</summary> public virtual StringBuilder Generate(StringBuilder?sb = null, int indent = 0) { sb = sb ?? new StringBuilder(); // Add the tag and attributes GenerateTagOpen(sb, ref indent); // Add the content. Note, using 'HasContent' because some // elements may have content other than stuff in 'm_elems' if (HasContent) { if (NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent : 0); } GenerateContent(sb, indent); if (NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent - 1 : 0); } } // Close the tag GenerateTagClose(sb, ref indent); return(sb); }
/// <summary>Add the content of this element to 'sb'</summary> protected virtual void GenerateContent(StringBuilder sb, int indent) { foreach (var x in Children) { x.Generate(sb, indent); if (x != Children.Back() && NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent : 0); } } }
protected override void GenerateTagClose(StringBuilder sb, ref int indent) { if (indent >= 0) { --indent; } sb.Append("</tdata>"); if (NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent - 1 : 0); } base.GenerateTagClose(sb, ref indent); }
protected override void GenerateTagOpen(StringBuilder sb, ref int indent) { base.GenerateTagOpen(sb, ref indent); if (NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent : 0); } sb.Append("<tdata>"); if (indent >= 0) { ++indent; } }
/// <summary>Add the content of this element to 'sb'</summary> protected override void GenerateContent(StringBuilder sb, int indent) { base.GenerateContent(sb, indent); var tabs = NewLine.HasValue() && indent >= 0 ? indent : 0; foreach (var x in Defs) { x.GenerateContent(sb, tabs, NewLine); if (x != Defs.Back() && NewLine.HasValue()) { sb.Append(NewLine).Append('\t', indent >= 0 ? indent : 0); } } }