public string GetHtml(Range r) { this.tb = r.tb; Dictionary <StyleIndex, object> styles = new Dictionary <StyleIndex, object>(); StringBuilder sb = new StringBuilder(); StringBuilder tempSB = new StringBuilder(); StyleIndex currentStyleId = StyleIndex.None; r.Normalize(); int currentLine = r.Start.iLine; styles[currentStyleId] = null; // if (UseOriginalFont) { sb.AppendFormat("<font style=\"font-family: {0}, monospace; font-size: {1}px; line-height: {2}px;\">", r.tb.Font.Name, r.tb.CharHeight - r.tb.LineInterval, r.tb.CharHeight); } // if (IncludeLineNumbers) { tempSB.AppendFormat("<span class=lineNumber>{0}</span> ", currentLine + 1); } // bool hasNonSpace = false; foreach (Place p in r) { Char c = r.tb[p.iLine][p.iChar]; if (c.style != currentStyleId) { Flush(sb, tempSB, currentStyleId); currentStyleId = c.style; styles[currentStyleId] = null; } if (p.iLine != currentLine) { for (int i = currentLine; i < p.iLine; i++) { tempSB.AppendLine(UseBr ? "<br>" : ""); if (IncludeLineNumbers) { tempSB.AppendFormat("<span class=lineNumber>{0}</span> ", i + 2); } } currentLine = p.iLine; hasNonSpace = false; } switch (c.c) { case ' ': if ((hasNonSpace || !UseForwardNbsp) && !UseNbsp) { goto default; } tempSB.Append(" "); break; case '<': tempSB.Append("<"); break; case '>': tempSB.Append(">"); break; case '&': tempSB.Append("&"); break; default: hasNonSpace = true; tempSB.Append(c.c); break; } } Flush(sb, tempSB, currentStyleId); if (UseOriginalFont) { sb.AppendLine("</font>"); } //build styles if (UseStyleTag) { tempSB.Length = 0; tempSB.AppendLine("<style type=\"text/css\">"); foreach (var styleId in styles.Keys) { tempSB.AppendFormat(".fctb{0}{{ {1} }}\r\n", GetStyleName(styleId), GetCss(styleId)); } tempSB.AppendLine("</style>"); sb.Insert(0, tempSB.ToString()); } if (IncludeLineNumbers) { sb.Insert(0, LineNumbersCSS); } return(sb.ToString()); }