public Convert ( |
||
reader | The text reader. | |
writer | The text writer. | |
Résultat | void |
protected override void VisitTextPart (TextPart entity) { string text; if (entity.IsHtml) { var converter = new HtmlToHtml { HtmlTagCallback = HtmlTagCallback }; text = converter.Convert (entity.Text); } else if (entity.IsFlowed) { var converter = new FlowedToText (); text = converter.Convert (entity.Text); text = QuoteText (text); } else { // quote the original message text text = QuoteText (entity.Text); } var part = new TextPart (entity.ContentType.MediaSubtype.ToLowerInvariant ()) { Text = text }; Push (part); }
public void TestSimpleHtmlToHtml () { string expected = File.ReadAllText ("../../TestData/html/xamarin3.xhtml"); string text = File.ReadAllText ("../../TestData/html/xamarin3.html"); var converter = new HtmlToHtml { HtmlTagCallback = ReplaceUrlsWithFileNames }; var result = converter.Convert (text); Assert.AreEqual (expected, result); }
void RenderMultipartRelated (MultipartRelated related) { var root = related.Root; var multipart = root as Multipart; var text = root as TextPart; if (multipart != null) { // Note: the root document can sometimes be a multipart/alternative. // A multipart/alternative is just a collection of alternate views. // The last part is the format that most closely matches what the // user saw in his or her email client's WYSIWYG editor. for (int i = multipart.Count; i > 0; i--) { var body = multipart[i - 1] as TextPart; if (body == null) continue; // our preferred mime-type is text/html if (body.ContentType.Matches ("text", "html")) { text = body; break; } if (text == null) text = body; } } // check if we have a text/html document if (text != null) { if (text.ContentType.Matches ("text", "html")) { // replace image src urls that refer to related MIME parts with "data:" urls // Note: we could also save the related MIME part content to disk and use // file:// urls instead. var ctx = new MultipartRelatedImageContext (related); var converter = new HtmlToHtml () { HtmlTagCallback = ctx.HtmlTagCallback }; var html = converter.Convert (text.Text); webBrowser.DocumentText = html; } else { RenderText (text); } } else if (root != null) { // we don't know what we have, so render it as an entity Render (root); } }