public void RoundTrip_SgmlReader36() { var html = @"<html> <head> <script language=""JavaScript""> <!-- --></script> </head> <body> <p>hello</p> </body> </html> "; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <head> <script language=""JavaScript""> <!-- --></script> </head> <body> <p>hello</p> </body> </html> ", rendered); } }
public void RoundTrip_Basic() { var html = @"<!DOCTYPE html> <html lang=""en""> <head> <meta charset=""utf-8""> <title>The HTML5 Herald</title> <meta name=""description"" content=""The HTML5 Herald""> <meta name=""author"" content=""SitePoint""> <link rel=""stylesheet"" href=""css/styles.css?v=1.0""> <!--[if lt IE 9]> <script src=""https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js""></script> <![endif]--> </head> <body> <input type=""text"" required> <script src=""js/scripts.js""></script> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(html, rendered); } }
private void TestParser(string data, string expected) { using (var reader = new HtmlReader(data)) { var rendered = reader.ToHtml(); Assert.Equal(expected, rendered); } }
public void RoundTrip_EntityName() { var html = @"<p>a±b</p>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<p>a±b</p>", rendered); } }
public void RoundTrip_SgmlReader22() { var html = @"<html><body>do <![if !supportLists]>not<![endif]> lose this text</body></html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html><body>do <![if !supportLists]>not<![endif]> lose this text</body></html>", rendered); } }
public void RoundTrip_VoidElementCloseTag() { var html = @"<p><img src></img></p>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<p><img src></p>", rendered); } }
public void RoundTrip_SgmlReader28() { var html = @"<html xmlns:o=""http://microsoft.com""><body>A<o:p></o:p>B<o:p></o:p></body></html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html xmlns:o=""http://microsoft.com""><body>A<o:p></o:p>B<o:p></o:p></body></html>", rendered); } }
public void RoundTrip_SgmlReader15() { var html = @"<html xmlns=""http://www.w3.org/1999/xhtml""><head /><body><table u1:str="""" x:str=""""></table></body></html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html xmlns=""http://www.w3.org/1999/xhtml""><head></head><body><table u1:str x:str></table></body></html>", rendered); } }
public void RoundTrip_SgmlReader39() { var html = @"<html><class=""black"">Text………</html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html><class=""black"">Text………</class=""black""></html>", rendered); } }
public void RoundTrip_SgmlReader46() { var html = @"blah <b>foo</b>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(html, rendered); } }
public void RoundTrip_SgmlReader60() { var html = @"<p>&#x;</p>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<p>&#x;</p>", rendered); } }
public void RoundTrip_SgmlReader24() { var html = @"<html xmlns:n=""http://explicit""><foo attr1=""1"" n:attr2=""2"" /><n:foo attr1=""1"" n:attr2=""2"" /></html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html xmlns:n=""http://explicit""><foo attr1=""1"" n:attr2=""2""></foo><n:foo attr1=""1"" n:attr2=""2""></n:foo></html>", rendered); } }
public void RoundTrip_SgmlReader33() { var html = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""> <html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""> <html>", rendered); } }
public void RoundTrip_SgmlReader11() { var html = @"<html> <body><a href=""http://www.cnn.com/""' title=""cnn.com"">cnn</a></body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body><a href=""http://www.cnn.com/"" title=""cnn.com"">cnn</a></body> </html>", rendered); } }
public void RoundTrip_SgmlReader09() { var html = @"<html> <body>This <P>is bad </P> XHTML.</body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body>This <p>is bad </p> XHTML.</body> </html>", rendered); } }
public void RoundTrip_SgmlReader55() { var html = @"<html> <body style=""&"<>'"">&"<>'</body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body style=""&"<>'"">&""<>'</body> </html>", rendered); } }
public void RoundTrip_SgmlReader41() { var html = @"<html> <img src=""img.gif"" height""4"" width= 2 > </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <img src=""img.gif"" height""4"" width=""2""> </html>", rendered); } }
public void RoundTrip_SgmlReader48() { var html = @"<html> <body> <p>ZZZ test Z</p>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body> <p>ZZZ test Z</p>", rendered); } }
public void RoundTrip_SciptTagWithXml() { var html = @"<script type=""text/xml""><first><another attr=""value"" /></first></script>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(html, rendered); } using (var reader = new HtmlReader(html)) { var rendered = reader.Minify().ToHtml(); Assert.Equal(html, rendered); } }
public void RoundTrip_SgmlReader34() { var html = @"<HTML><BODY> <LINK href=""a.css"" type=""text/css"" rel=""stylesheet"" /> </body> </HTML> "; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html><body> <link href=""a.css"" type=""text/css"" rel=""stylesheet""> </body> </html> ", rendered); } }
public void RoundTrip_SgmlReader03() { var html = @"<html> <body><span text=""foo<bar""/> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body><span text=""foo<bar""></span> </body> </html>", rendered); } }
public void RoundTrip_Word() { 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""> <body lang=EN-US style='tab-interval:.5in'> <div class=WordSection1> <p class=MsoNormal>Test <b style='mso-bidi-font-weight:normal'>document<o:p></o:p></b></p> <p class=MsoListParagraphCxSpFirst style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family: Symbol'><span style='mso-list:Ignore'>·<span style='font:7.0pt ""Times New Roman""'> </span></span></span><![endif]>With bullets</p> </div> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<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""> <body lang=""EN-US"" style=""tab-interval:.5in""> <div class=""WordSection1""> <p class=""MsoNormal"">Test <b style=""mso-bidi-font-weight:normal"">document<o:p></o:p></b></p> <p class=""MsoListParagraphCxSpFirst"" style=""text-indent:-.25in;mso-list:l0 level1 lfo1""><![if !supportLists]><span style=""font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family: Symbol""><span style=""mso-list:Ignore"">·<span style=""font:7.0pt "Times New Roman"""> </span></span></span><![endif]>With bullets</p> </div> </body> </html>", rendered); } }
public void RoundTrip_SgmlReader08() { var html = @"<html> <body> <script type=""text/javascript"">/*<![CDATA[*/ var test = '<div>""test""</div>'; /*]]>*/</script> <p>test</p> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(html, rendered); } }
public void RoundTrip_SgmlReader18() { var html = @"<html> <body> <script type=""text/javascript"">/*<![CDATA[*/ /*<![CDATA[*/ test /*]]>*/ /*]]>*/</script> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body> <script type=""text/javascript"">/*<![CDATA[*/ /*<![CDATA[*/ test /*]]>*/ /*]]>*/</script> </body> </html>", rendered); } }
public void RoundTrip_SgmlReader05() { var html = @"<html> <body> <p>bad char: <span>􀀀</span></p> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body> <p>bad char: <span></span></p> </body> </html>", rendered); } }
public void RoundTrip_SgmlReader07() { var html = @"<html> <body> <DIV STYLE=""top:214px; left:139px; position:absolute; font-size:26px;""><NOBR><SPAN STYLE=""font-family:""Wingdings 2"";""></SPAN></NOBR></DIV> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body> <div style=""top:214px; left:139px; position:absolute; font-size:26px;""><nobr><span style=""font-family:"" wingdings 2"";""></span></nobr></div> </body> </html>", rendered); } }
public void RoundTrip_SgmlReader04() { var html = @"<html> <body> <tag>&test   blah blah</tag> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html> <body> <tag>&test blah blah</tag> </body> </html>", rendered); } }
public void RoundTrip_Svg() { var html = @"<html> <head> <title>SVG test</title> <meta name=""description"" content=""The HTML5 Herald""> <meta name=""author"" content=""SitePoint""> </head> <body> <input type=""checkbox"" checked> <svg version=""1.1"" id=""Layer_1"" xmlns=""http://www.w3.org/2000/svg"" xmlns:xlink=""http://www.w3.org/1999/xlink"" x=""0px"" y=""0px"" width=""612px"" height=""502.174px"" viewBox=""0 65.326 612 502.174"" enable-background=""new 0 65.326 612 502.174"" xml:space=""preserve"" class=""logo""> <ellipse class=""ground"" cx=""283.5"" cy=""487.5"" rx=""259"" ry=""80"" /> <path class=""kiwi"" d=""M210.333,65.331C104.367,66.105-12.349,150.637,1.056,276.449c4.303,40.393,18.533,63.704,52.171,79.03 c36.307,16.544,57.022,54.556,50.406,112.954c-9.935,4.88-17.405,11.031-19.132,20.015c7.531-0.17,14.943-0.312,22.59,4.341 c20.333,12.375,31.296,27.363,42.979,51.72c1.714,3.572,8.192,2.849,8.312-3.078c0.17-8.467-1.856-17.454-5.226-26.933 c-2.955-8.313,3.059-7.985,6.917-6.106c6.399,3.115,16.334,9.43,30.39,13.098c5.392,1.407,5.995-3.877,5.224-6.991 c-1.864-7.522-11.009-10.862-24.519-19.229c-4.82-2.984-0.927-9.736,5.168-8.351l20.234,2.415c3.359,0.763,4.555-6.114,0.882-7.875 c-14.198-6.804-28.897-10.098-53.864-7.799c-11.617-29.265-29.811-61.617-15.674-81.681c12.639-17.938,31.216-20.74,39.147,43.489 c-5.002,3.107-11.215,5.031-11.332,13.024c7.201-2.845,11.207-1.399,14.791,0c17.912,6.998,35.462,21.826,52.982,37.309 c3.739,3.303,8.413-1.718,6.991-6.034c-2.138-6.494-8.053-10.659-14.791-20.016c-3.239-4.495,5.03-7.045,10.886-6.876 c13.849,0.396,22.886,8.268,35.177,11.218c4.483,1.076,9.741-1.964,6.917-6.917c-3.472-6.085-13.015-9.124-19.18-13.413 c-4.357-3.029-3.025-7.132,2.697-6.602c3.905,0.361,8.478,2.271,13.908,1.767c9.946-0.925,7.717-7.169-0.883-9.566 c-19.036-5.304-39.891-6.311-61.665-5.225c-43.837-8.358-31.554-84.887,0-90.363c29.571-5.132,62.966-13.339,99.928-32.156 c32.668-5.429,64.835-12.446,92.939-33.85c48.106-14.469,111.903,16.113,204.241,149.695c3.926,5.681,15.819,9.94,9.524-6.351 c-15.893-41.125-68.176-93.328-92.13-132.085c-24.581-39.774-14.34-61.243-39.957-91.247 c-21.326-24.978-47.502-25.803-77.339-17.365c-23.461,6.634-39.234-7.117-52.98-31.273C318.42,87.525,265.838,64.927,210.333,65.331 z M445.731,203.01c6.12,0,11.112,4.919,11.112,11.038c0,6.119-4.994,11.111-11.112,11.111s-11.038-4.994-11.038-11.111 C434.693,207.929,439.613,203.01,445.731,203.01z"" /> <filter id=""pictureFilter""> <feGaussianBlur stdDeviation=""15"" /> </filter> </svg> <script src=""file.js""></script> </body> </html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(html, rendered); } }
public string ParseHTML(string html) { var sb = new StringBuilder(); sb.EnsureCapacity(html.Length); var settings = new MarkdownWriterSettings() { NewLineChars = "\n" }; using (var sw = new StringWriter(sb)) using (var reader = new HtmlReader(html, false)) using (var writer = new TextileWriter(sw, settings)) { reader.ToHtml(writer); sw.Flush(); return(sb.ToString()); } }
public void RoundTrip_SgmlReader21() { var html = @"<html><body> <p class=""MsoNormal""> <span style=""font-size: 10pt;"" arial="""" ,="""" sans-serif="""" ;;="""" font-family:dummy:="""" font-family:="""" font-family:foo:="""" arial;="""" font-size:="""" 13.3333px;=""""> <span class=""Apple-style-span"" style=""font-family: Arial; font-size: 13.3333px;"">-lm</span> </span> </p> </body></html>"; using (var reader = new HtmlReader(html)) { var rendered = reader.ToHtml(); Assert.Equal(@"<html><body> <p class=""MsoNormal""> <span style=""font-size: 10pt;"" arial , sans-serif ;; font-family:dummy: font-family: font-family:foo: arial; font-size: 13.3333px;> <span class=""Apple-style-span"" style=""font-family: Arial; font-size: 13.3333px;"">-lm</span> </span> </p> </body></html>", rendered); } }