public void ToString(StringBuilder strBuilder, int level) { //strBuilder.AppendLine(); strIndent(strBuilder, level); strBuilder.Append(@"<li>"); strBuilder.Append(@"<a"); string uid = (RealSectioningRootOrContent != null ? RealSectioningRootOrContent.GetXmlElementId() : null); if (Heading != null) { string headingName = Heading.GetXmlElementLocalName(); if (!string.IsNullOrEmpty(headingName) && headingName.Equals(@"hgroup", StringComparison.OrdinalIgnoreCase)) { TreeNode highestRanked = null; int highestRank = int.MaxValue; foreach (TreeNode child in Heading.Children.ContentsAs_Enumerable) { string name = child.GetXmlElementLocalName(); int rank = GetHeadingRank(name); if (rank >= 0 && rank < highestRank) { highestRank = rank; highestRanked = child; } } if (highestRanked != null) { if (string.IsNullOrEmpty(uid)) { uid = Heading.GetXmlElementId(); if (string.IsNullOrEmpty(uid)) { uid = highestRanked.GetXmlElementId(); } } if (!string.IsNullOrEmpty(uid)) { strBuilder.Append(" href=\"#" + uid + "\""); } strBuilder.Append(@">"); strBuilder.Append(highestRanked.GetTextFlattened()); } else { Debugger.Break(); if (string.IsNullOrEmpty(uid)) { uid = Heading.GetXmlElementId(); } if (!string.IsNullOrEmpty(uid)) { strBuilder.Append(" href=\"#" + uid + "\""); } strBuilder.Append(@">"); strBuilder.Append(Heading.GetTextFlattened()); } } else { if (string.IsNullOrEmpty(uid)) { uid = Heading.GetXmlElementId(); } if (!string.IsNullOrEmpty(uid)) { strBuilder.Append(" href=\"#" + uid + "\""); } strBuilder.Append(@">"); strBuilder.Append(Heading.GetTextFlattened()); } } else { if (!string.IsNullOrEmpty(uid)) { strBuilder.Append(" href=\"#" + uid + "\""); } strBuilder.Append(@">"); if (RealSectioningRootOrContent != null) { string name = RealSectioningRootOrContent.GetXmlElementPrefixedLocalName(); if (name.Equals(@"body")) { strBuilder.Append(@"Untitled document"); } else if (name.Equals(@"section")) { strBuilder.Append(@"Untitled section"); } else if (name.Equals(@"article")) { strBuilder.Append(@"Article"); } else if (name.Equals(@"aside")) { strBuilder.Append(@"Sidebar"); } else if (name.Equals(@"nav")) { strBuilder.Append(@"Navigation"); } else { strBuilder.Append(@"UNTITLED ("); strBuilder.Append(name); strBuilder.Append(@")"); } } else { strBuilder.Append(@"UNTITLED"); } } strBuilder.Append(@"</a>"); if (SubSections.Count > 0) { strBuilder.AppendLine(); strIndent(strBuilder, level + 1); strBuilder.AppendLine(@"<ol>"); foreach (Section section in SubSections) { DebugFix.Assert(section.ParentSection == this); section.ToString(strBuilder, level + 2); } //strBuilder.AppendLine(); strIndent(strBuilder, level + 1); strBuilder.AppendLine(@"</ol>"); strIndent(strBuilder, level); } strBuilder.AppendLine("</li>"); }