public static void TestClassNormalization() { string stringToUse = Values.QuoteFail; HtmlFragmentViewModel vm = new HtmlFragmentViewModel(stringToUse, true); Console.WriteLine(vm.HtmlSource); }
public static void TestBadSlashdotKnockout() { string stringToUse = Values.SlashdotMoreFail; HtmlFragmentViewModel vm = new HtmlFragmentViewModel(stringToUse, true, INLINE_STYLE_OPERATIONS.CONSOLIDATE_STYLES_AND_REMOVE_COLORS); string stamp = DateTime.Now.ToString("yyyy-MM-dd_HHmmss.fff"); File.WriteAllText($@"C:\temp\html\htmlFrag_{stamp}.html", vm.StyleBlock + Environment.NewLine + vm.ClippedSource); Console.WriteLine(vm.HtmlSource); }
public static void TestTitle() { bool pass = true; HtmlFragmentViewModel vmEdge = new HtmlFragmentViewModel(EdgeFragment); HtmlFragmentViewModel vmChrome = new HtmlFragmentViewModel(ChromeFragment); pass = pass && vmEdge.PageTitle.Equals("Daring Fireball: Walt Mossberg: ‘Why Does Siri Seem So Dumb?’"); pass = pass && vmChrome.PageTitle.Equals("daringfireball.net"); if (!pass) { throw new Exception("TestTitle check did not pass successfully."); } }
// Very basic unit test. You get the idea. Test away. public static void TestSanity() { bool pass = true; string testSource = @"Version:0.9 StartHTML:0000000196 EndHTML:0000000845 StartFragment:0000000232 EndFragment:0000000809 SourceURL:https://msdn.microsoft.com/en-us/library/windows/desktop/ms649015(v=vs.85).aspx <html> <body> <!--StartFragment--><span style=""color: rgb(69, 69, 69); font-family: "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;"">The official name of the clipboard (the string used by RegisterClipboardFormat) is HTML Format.</span><!--EndFragment--> </body> </html>"; HtmlFragmentViewModel vm = new HtmlFragmentViewModel(testSource, false); pass = pass & vm.Version.Equals("0.9"); pass = pass && vm.StartHtml.Equals(196); pass = pass && vm.EndHtml.Equals(845); pass = pass && vm.StartFragment.Equals(232); pass = pass && vm.EndFragment.Equals(809); pass = pass && vm.SourceUrl.Equals("https://msdn.microsoft.com/en-us/library/windows/desktop/ms649015(v=vs.85).aspx"); // Note that if we had blank lines in here, they'd be removed on construction as currently written (20161029). pass = pass && vm.ClippedSource.Equals(@"<span style=""color: rgb(69, 69, 69); font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;"">The official name of the clipboard (the string used by RegisterClipboardFormat) is HTML Format.</span>"); string expectedHtml = @"<html> <body> <!--StartFragment--><span style=""color: rgb(69, 69, 69); font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;"">The official name of the clipboard (the string used by RegisterClipboardFormat) is HTML Format.</span><!--EndFragment--> </body> </html>"; expectedHtml.NLWriteLine(); vm.HtmlSource.NLWriteLine(); pass = pass && vm.HtmlSource.Equals(expectedHtml); pass = pass & vm.SourceUrlDomainSecondAndTopLevelsOnly.Equals("microsoft.com"); if (!pass) { throw new Exception("TestSanity check test did not pass successfully."); } }
static void Main(string[] args) { Console.SetWindowSize(100, 40); string response = ""; while (!response.Equals(".")) { try { HtmlFragmentViewModel pixelate = new HtmlFragmentViewModel(Values.Pixelating, true, INLINE_STYLE_OPERATIONS.CONSOLIDATE_STYLES_AND_REMOVE_COLORS); Console.WriteLine(pixelate.StyleBlock); Console.WriteLine(pixelate.HtmlSource); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("================================"); Console.WriteLine(""); Console.WriteLine(""); //HtmlFragmentViewModel vmChromeStripColor1 = new HtmlFragmentViewModel(Program.ChromeFragment); //File.WriteAllText(@"C:\temp\withStrip.html", vmChromeStripColor1.ClippedSource.Replace("<", "\n<")); //HtmlFragmentViewModel vmChromeNoStrip = new HtmlFragmentViewModel(Program.ChromeFragment, false); //File.WriteAllText(@"C:\temp\withoutStrip.html", vmChromeNoStrip.ClippedSource.Replace("<", "\n<")); //Program.TestSanity(); //Program.TestTitle(); //Program.TestClassNormalization(); string tag = @"<a href=""http://www.google.com"" class="""" style="""">"; //Console.WriteLine(tag.RetrieveAttribute("class", true)); //Console.WriteLine(tag.RetrieveAttribute("style", true)); //Console.WriteLine(tag.RetrieveAttribute("class", false)); //Console.WriteLine(tag.RetrieveAttribute("style", false)); //tag = @"<span class=""topic"" style=""box-sizing: border-box; margin: 0px; padding: 0px; overflow: hidden; height: 40px; width: auto; position: absolute; top: 12px; right: 70px; max-width: 100px;"">"; //Console.WriteLine(tag.RetrieveAttribute("class", true)); //Console.WriteLine(tag.RetrieveAttribute("style", true)); //tag = @"<span id=""title-99902227"" class=""story-title"" style=""box-sizing: border-box; margin: 0px; padding: 0px; left: 15px; position: relative; color: white;"">"; //Console.WriteLine(tag.RetrieveAttribute("class", true)); //Console.WriteLine(tag.RetrieveAttribute("style", true)); //Program.TestBadSlashdotKnockout(); //====================================================== #region A more real world use case //====================================================== //HtmlFragmentViewModel vmEdge = new HtmlFragmentViewModel(EdgeFragment); //string strIntroLink = string.Empty; //if (vmEdge.SourceUrl.Length > 0 && vmEdge.SourceUrlDomainSecondAndTopLevelsOnly.Length > 0) //{ // strIntroLink = string.Format("From <a href=\"{0}\">{1}</a>:" + Environment.NewLine + Environment.NewLine, // vmEdge.SourceUrl, vmEdge.SourceUrlDomainSecondAndTopLevelsOnly); //} //Console.WriteLine(strIntroLink + vm.HtmlSource); //====================================================== #endregion A more real world use case //====================================================== } catch (Exception ex) { Console.WriteLine("Error: " + ex.ToString()); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("======================================================"); Console.WriteLine("Test finished. Period on line by itself to end."); Console.WriteLine("======================================================"); response = Console.ReadLine(); } }