public void TestBrokenQuotedFlowedToHtml() { // Note: this is the brokenly quoted sample from rfc3676 at the end of section 4.5 string expected = "<blockquote><p>Thou villainous ill-breeding spongy dizzy-eyed reeky elf-skinned pigeon-egg! </p>" + Environment.NewLine + "<blockquote><p>Thou artless swag-bellied milk-livered dismal-dreaming idle-headed scut!</p>" + Environment.NewLine + "<blockquote><p>Thou errant folly-fallen spleeny reeling-ripe unmuzzled ratsbane!</p>" + Environment.NewLine + "<blockquote><p>Henceforth, the coding style is to be strictly enforced, including the use of only upper case.</p>" + Environment.NewLine + "<blockquote><p>I've noticed a lack of adherence to the coding styles, of late.</p>" + Environment.NewLine + "<blockquote><p>Any complaints?</p>" + Environment.NewLine + "</blockquote></blockquote></blockquote></blockquote></blockquote></blockquote>"; string text = "> Thou villainous ill-breeding spongy dizzy-eyed " + Environment.NewLine + "> reeky elf-skinned pigeon-egg! " + Environment.NewLine + ">> Thou artless swag-bellied milk-livered " + Environment.NewLine + ">> dismal-dreaming idle-headed scut!" + Environment.NewLine + ">>> Thou errant folly-fallen spleeny reeling-ripe " + Environment.NewLine + ">>> unmuzzled ratsbane!" + Environment.NewLine + ">>>> Henceforth, the coding style is to be strictly " + Environment.NewLine + ">>>> enforced, including the use of only upper case." + Environment.NewLine + ">>>>> I've noticed a lack of adherence to the coding " + Environment.NewLine + ">>>>> styles, of late." + Environment.NewLine + ">>>>>> Any complaints?" + Environment.NewLine; var converter = new FlowedToHtml { OutputHtmlFragment = true }; var result = converter.Convert(text); Assert.AreEqual(expected, result); }
void RenderText(TextPart text) { string html; if (text.IsHtml) { // the text content is already in HTML format html = text.Text; } else if (text.IsFlowed) { var converter = new FlowedToHtml(); string delsp; // the delsp parameter specifies whether or not to delete spaces at the end of flowed lines if (!text.ContentType.Parameters.TryGetValue("delsp", out delsp)) { delsp = "no"; } if (string.Compare(delsp, "yes", StringComparison.OrdinalIgnoreCase) == 0) { converter.DeleteSpace = true; } html = converter.Convert(text.Text); } else { html = new TextToHtml().Convert(text.Text); } webView.LoadData(html, "text/html", "utf-8"); }
public void TestTextHeaderAndFooter() { string expected = "<html><body>On <date>, so-and-so said:<br/><blockquote><p>Thou villainous ill-breeding spongy dizzy-eyed reeky elf-skinned pigeon-egg!</p>" + Environment.NewLine + "<blockquote><p>Thou artless swag-bellied milk-livered dismal-dreaming idle-headed scut!</p>" + Environment.NewLine + "<blockquote><p>Thou errant folly-fallen spleeny reeling-ripe unmuzzled ratsbane!</p>" + Environment.NewLine + "<blockquote><p>Henceforth, the coding style is to be strictly enforced, including the use of only upper case.</p>" + Environment.NewLine + "<blockquote><p>I've noticed a lack of adherence to the coding styles, of late.</p>" + Environment.NewLine + "<blockquote><p>Any complaints?</p>" + Environment.NewLine + "</blockquote></blockquote></blockquote></blockquote></blockquote></blockquote>Tha-tha-tha-tha that's all, folks!<br/></body></html>"; string text = "> Thou villainous ill-breeding spongy dizzy-eyed " + Environment.NewLine + "> reeky elf-skinned pigeon-egg!" + Environment.NewLine + ">> Thou artless swag-bellied milk-livered " + Environment.NewLine + ">> dismal-dreaming idle-headed scut!" + Environment.NewLine + ">>> Thou errant folly-fallen spleeny reeling-ripe " + Environment.NewLine + ">>> unmuzzled ratsbane!" + Environment.NewLine + ">>>> Henceforth, the coding style is to be strictly " + Environment.NewLine + ">>>> enforced, including the use of only upper case." + Environment.NewLine + ">>>>> I've noticed a lack of adherence to the coding " + Environment.NewLine + ">>>>> styles, of late." + Environment.NewLine + ">>>>>> Any complaints?" + Environment.NewLine; var converter = new FlowedToHtml { Header = "On <date>, so-and-so said:" + Environment.NewLine, HeaderFormat = HeaderFooterFormat.Text, Footer = "Tha-tha-tha-tha that's all, folks!" + Environment.NewLine, FooterFormat = HeaderFooterFormat.Text, HtmlTagCallback = null }; var result = converter.Convert(text); Assert.AreEqual(expected, result); }
public void TestSimpleFlowedToHtml() { string expected = "<p>This is some sample text that has been formatted " + "according to the format=flowed rules defined in rfc3676. " + "This text, once converted, should all be on a single line.</p>" + Environment.NewLine + "<br/>" + Environment.NewLine + "<br/>" + Environment.NewLine + "<br/>" + Environment.NewLine + "<br/>" + Environment.NewLine + "<p>And this line of text should be separate by 4 blank lines.</p>" + Environment.NewLine; string text = "This is some sample text that has been formatted " + Environment.NewLine + "according to the format=flowed rules defined in rfc3676. " + Environment.NewLine + "This text, once converted, should all be on a single line." + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + "And this line of text should be separate by 4 blank lines." + Environment.NewLine; var converter = new FlowedToHtml { OutputHtmlFragment = true }; var result = converter.Convert(text); Assert.AreEqual(expected, result); }
string RenderText(TextPart text) { string html; if (text.IsHtml) { return(text.Text); } else if (text.IsFlowed) { var converter = new FlowedToHtml(); string delsp; if (!text.ContentType.Parameters.TryGetValue("delsp", out delsp)) { delsp = "no"; } if (string.Compare(delsp, "yes", StringComparison.OrdinalIgnoreCase) == 0) { converter.DeleteSpace = true; } html = converter.Convert(text.Text); } else { html = new TextToHtml().Convert(text.Text); } return(html); }
static void RenderText(TextPart text, WebBrowserEditabil pWebBrowser) { string html; if (text.IsHtml) { html = text.Text; } else if (text.IsFlowed) { var converter = new FlowedToHtml(); string delsp; if (!text.ContentType.Parameters.TryGetValue("delsp", out delsp)) { delsp = "no"; } if (string.Compare(delsp, "yes", StringComparison.OrdinalIgnoreCase) == 0) { converter.DeleteSpace = true; } html = converter.Convert(text.Text); } else { html = new TextToHtml().Convert(text.Text); } pWebBrowser.DocumentText = html; }
public void TestSimpleFlowedWithUrlsToHtml() { string expected = "<p>Check out <a href=\"http://www.xamarin.com\">http://www.xamarin.com</a> - it's amazing!</p>" + Environment.NewLine; string text = "Check out http://www.xamarin.com - it's amazing!" + Environment.NewLine; var converter = new FlowedToHtml(); var result = converter.Convert(text); Assert.AreEqual(expected, result); }
public void TestArgumentExceptions() { var converter = new FlowedToHtml(); var reader = new StringReader(""); var writer = new StringWriter(); Assert.Throws <ArgumentNullException> (() => converter.InputEncoding = null); Assert.Throws <ArgumentNullException> (() => converter.OutputEncoding = null); Assert.Throws <ArgumentOutOfRangeException> (() => converter.InputStreamBufferSize = -1); Assert.Throws <ArgumentOutOfRangeException> (() => converter.OutputStreamBufferSize = -1); Assert.Throws <ArgumentNullException> (() => converter.Convert(null)); Assert.Throws <ArgumentNullException> (() => converter.Convert((Stream)null, Stream.Null)); Assert.Throws <ArgumentNullException> (() => converter.Convert(Stream.Null, (Stream)null)); Assert.Throws <ArgumentNullException> (() => converter.Convert((TextReader)null, Stream.Null)); Assert.Throws <ArgumentNullException> (() => converter.Convert(Stream.Null, (TextWriter)null)); Assert.Throws <ArgumentNullException> (() => converter.Convert((TextReader)null, writer)); Assert.Throws <ArgumentNullException> (() => converter.Convert(reader, (TextWriter)null)); Assert.Throws <ArgumentNullException> (() => converter.Convert(new StreamReader(Stream.Null), (Stream)null)); Assert.Throws <ArgumentNullException> (() => converter.Convert((Stream)null, new StreamWriter(Stream.Null))); Assert.Throws <ArgumentNullException> (() => converter.Convert(new StreamReader(Stream.Null), (TextWriter)null)); }
private void SetFlowedHtmlToBody(TextPart entity) { var beforeAfter = GetBeforeAfterFormatWrapper(UIStrings.HtmlToHtmlFormatWrapper); var convertor = new FlowedToHtml { Header = $"{UIStrings.MarkOfTheWeb}{Environment.NewLine}{beforeAfter.Before}", HeaderFormat = HeaderFooterFormat.Html, Footer = beforeAfter.After, FooterFormat = HeaderFooterFormat.Html }; if (entity.ContentType.Parameters.TryGetValue("delsp", out string delsp)) { convertor.DeleteSpace = delsp.ToLowerInvariant() == "yes"; } _body = convertor.Convert(entity.Text); }