SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

AvalonEdit: Export Text As HTML

Last post 02-16-2010 5:35 PM by M.Holder. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-15-2010 10:08 PM

    AvalonEdit: Export Text As HTML

     Hello,

    I have found the sample "HTMLSyntaxColorizer" in a SVN download of #Develop. I like it very much, but i need it for the AvalonEdit Control. I know theres a method called ToHTML(), but i dont how to use it.

    Are there any samples for AvalonEdit and Html? Can someone post some code?

     

    Bye

    Sorry for my english, im german

  • 02-16-2010 2:04 PM In reply to

    Re: AvalonEdit: Export Text As HTML

    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, nullnew 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>");
    }

  • 02-16-2010 5:35 PM In reply to

    Re: AvalonEdit: Export Text As HTML

     It would be great, when you´ll update the HTMLSyntaxColorizer sample.

    Your code helped me a lot. Thanks.

Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.