");
if (ShowLineNumbers) {
b.Append("');
b.Append(lineNumber.ToString().PadLeft(longestNumberLength));
b.Append(": ");
b.Append("");
}
if (lineSegment.Words.Count == 0) {
b.Append(" ");
} else {
PrintWords(lineSegment, b);
}
b.AppendLine("
");
lineNumber++;
}
b.AppendLine(""); foreach (LineSegment lineSegment in document.LineSegmentCollection) { PrintWords(lineSegment, b); b.AppendLine(); } b.AppendLine(""); } return b.ToString(); } void PrintWords(LineSegment lineSegment, StringBuilder b) { string currentSpan = null; foreach (TextWord word in lineSegment.Words) { if (word.Type == TextWordType.Space) { b.Append(' '); } else if (word.Type == TextWordType.Tab) { b.Append('\t'); } else { string newSpan = GetStyle(word); if (currentSpan != newSpan) { if (currentSpan != null) b.Append(""); if (newSpan != null) { b.Append("'); } currentSpan = newSpan; } b.Append(HtmlEncode(word.Word)); } } if (currentSpan != null) b.Append(""); } static string HtmlEncode(string word) { return word.Replace("&", "&").Replace("<", "<").Replace(">", ">"); } void WriteStyle(string style, StringBuilder b) { if (CreateStylesheet) { b.Append(" class=\""); b.Append(GetClass(style)); b.Append('"'); } else { b.Append(" style='"); b.Append(style); b.Append("'"); } } string GetStyle(TextWord word) { if (word.SyntaxColor == null || word.SyntaxColor.ToString() == currentDefaultTextColor.ToString()) return null; string style = "color: " + ColorToString(word.Color) + ";"; if (word.Bold) { style += " font-weight: bold;"; } if (word.Italic) { style += " font-style: italic;"; } if (word.SyntaxColor.HasBackground) { style += " background-color: " + ColorToString(word.SyntaxColor.BackgroundColor) + ";"; } return style; } static string ColorToString(System.Drawing.Color color) { return "#" + color.R.ToString("x2") + color.G.ToString("x2") + color.B.ToString("x2"); } } }