Exemplo n.º 1
0
        public void MustProcessHtmlWithScriptTag()
        {
            var html      = @"
            <html xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:w=""urn:schemas-microsoft-com:office:word"" xmlns:m=""http://schemas.microsoft.com/office/2004/12/omml"" xmlns=""http://www.w3.org/TR/REC-html40"">
                <head>
                    <style>
                        * {behavior:url(#default#VML);}
                    </style>
                </head>
                <body lang=PT-BR link=""#0563C1"" vlink=""#954F72"">
                    <div class=WordSection1>
                        <p class=MsoNormal>Vamos colocar uma imagem supimpa???<o:p></o:p></p>
                        <p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><span style='mso-fareast-language:PT-BR'>
                        <img width=248 height=628 id=""Imagem_x0020_1"" src=""cid:[email protected]""></span><o:p></o:p></p>
                    </div>
                </body>
                <script>
                    function test(){
                        alert('This is a Test');
                    }
                </script>
            </html>";
            var converter = new HtmlToText(html);

            Assert.Equal("Vamos colocar uma imagem supimpa???", converter.GetText());
        }
Exemplo n.º 2
0
        public void MustProcessHtmlWithComment()
        {
            var html      = @"<html xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:w=""urn:schemas-microsoft-com:office:word"" xmlns:m=""http://schemas.microsoft.com/office/2004/12/omml"" xmlns=""http://www.w3.org/TR/REC-html40""><head><meta http-equiv=Content-Type content=""text/html; charset=iso-8859-1""><meta name=Generator content=""Microsoft Word 15 (filtered medium)""><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:""Calibri"",sans-serif;
	mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#0563C1;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
span.EstiloDeEmail17
	{mso-style-type:personal-compose;
	font-family:""Calibri"",sans-serif;
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:""Calibri"",sans-serif;
	mso-fareast-language:EN-US;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=""edit"" spidmax=""1026"" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=""edit"">
<o:idmap v:ext=""edit"" data=""1"" />
</o:shapelayout></xml><![endif]--></head><body lang=PT-BR link=""#0563C1"" vlink=""#954F72""><div class=WordSection1><p class=MsoNormal>Vamos colocar uma imagem supimpa???<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><span style='mso-fareast-language:PT-BR'><img width=248 height=628 id=""Imagem_x0020_1"" src=""cid:[email protected]""></span><o:p></o:p></p></div></body></html>";
            var converter = new HtmlToText(html);

            Assert.Equal("Vamos colocar uma imagem supimpa???", converter.GetText());
        }
Exemplo n.º 3
0
        public void MustProcessHtmlWithMultilineString()
        {
            var html      = @"<html><head>
<meta http-equiv=""content-type"" content=""text/html; charset=utf-8""></head>
<body dir=""auto"">
<div>Boa tarde,</div><div><br></div>
<div>Gostaria de saber valores em caso de alteracao do voo de volta para quinta feira final do dia.</div>
<div>Voo direto para sdu ou galeao.</div>
<div>Favor sinalizar voo a partir das 18h com menor valor</div>
<div><br></div>
<div>Obrigada<br><br><div>Sent from my iPhone</div></div><div><br>";
            var converter = new HtmlToText(html);
            var result    = converter.GetText();

            Assert.Contains("\r\n", result);
        }
Exemplo n.º 4
0
        public void MustProcessHtmlWithUnicodeChars()
        {
            // TODO: A string criada abaixo não está representando um texto unicode real. Verificar para validar.
            var html      = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes(@"
            <html xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:w=""urn:schemas-microsoft-com:office:word"" xmlns:m=""http://schemas.microsoft.com/office/2004/12/omml"" xmlns=""http://www.w3.org/TR/REC-html40"">
                <head>
                    <style>
                        * {behavior:url(#default#VML);}
                    </style>
                </head>
                <body lang=PT-BR link=""#0563C1"" vlink=""#954F72"">
                    <p class=3DMsoNormal>Esta mensagem foi verificada pelo sistema de antivírus e  acredita-se estar livre de perigo.</p>
                </body>
                <script>
                    function test(){
                        alert('This is a Test');
                    }
                </script>
            </html>"));
            var converter = new HtmlToText(html);
            var result    = converter.GetText();

            Assert.Equal("Esta mensagem foi verificada pelo sistema de antivírus e  acredita-se estar livre de perigo.", result);
        }