I'll update the HTMLSyntaxColorizer example.
The easiest solution is to use the "HtmlClipboard" class (used in AvalonEdit when copying text to the clipboard):
TextDocument document = new TextDocument(code);
IHighlightingDefinition highlightDefinition = HighlightingManager.Instance.GetDefinition("C#");
IHighlighter highlighter = new DocumentHighlighter(document, highlightDefinition.MainRuleSet);
string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, null, new HtmlOptions());
If you need more control over the output (e.g. if you want to add line numbers or alternating background color), you can also iterate through all lines and convert them individually:
for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
HighlightedLine line = highlighter.HighlightLine(lineNumber);
output.Append(line.ToHtml(new HtmlOptions()));
output.AppendLine("<br>");
}