C# HTML from WebBrowser to valid XHTML

前端 未结 1 1011
悲哀的现实
悲哀的现实 2021-01-03 05:39

So, we are using a webBrowser control in edit mode, to allow people to enter text, and then take that text and send it out to the server for everyone to see. IE, it\'s an H

相关标签:
1条回答
  • 2021-01-03 06:31

    Would reccomend using either something like TinyMCE or HtmlAgilityPack (available as a Nuget package or from codeplex).

    TinyMCE allows users to perform a rich text edit with appropriate formatting controls, and will output the resultant Html.

    HtmlAgilityPAck on the other hand is a library that will allow you to pass in the HtmlStream generated by your method, and output this as a valid Xhtml stream.

    Rough example for working with this in the HtmlAgilityPAck as below:

    var sb = new StringBuilder(); 
    var stringWriter = new StringWriter(sb);
    
    string input = "<html><body><p>This is some test test<ul><li>item 1<li>item2<</ul></body>";
    
    var test = new HtmlAgilityPack.HtmlDocument();
    test.LoadHtml(input);
    test.OptionOutputAsXml = true;
    test.OptionCheckSyntax = true;
    test.OptionFixNestedTags = true;
    
    test.Save(stringWriter);
    
    Console.WriteLine(sb.ToString());
    
    0 讨论(0)
提交回复
热议问题