public void TagDataTagData() { reader = HtmlReaderFactory.FromString("<br/>a<p/>b", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Tag, reader.TokenKind); Assert.AreEqual("br", reader.Name); Assert.IsTrue(reader.SelfClosingElement); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Text, reader.TokenKind); Assert.AreEqual("a", reader.Text); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Tag, reader.TokenKind); Assert.AreEqual("p", reader.Name); Assert.IsTrue(reader.SelfClosingElement); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Text, reader.TokenKind); Assert.AreEqual("b", reader.Text); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public void Line_ReadParagraphStartTagOnFirstLine_ReturnsOne() { CreateReader("<p>"); reader.Read(); int line = reader.Line; Assert.AreEqual(1, line); }
public void AttributeValueNamedCharacterReference() { reader = HtmlReaderFactory.FromString("<a title=\"<\">", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual("<", reader.GetAttribute("title")); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public void DataHexCharacterReference() { reader = HtmlReaderFactory.FromString("A", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Text, reader.TokenKind); Assert.AreEqual("A", reader.Text); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public void BogusCommentState2() { reader = HtmlReaderFactory.FromString("<!/div>", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Comment, reader.TokenKind); Assert.AreEqual("/div", reader.Text); Assert.IsFalse(reader.Read()); Assert.AreEqual(1, parseErrors.Count); }
public void Data() { reader = HtmlReaderFactory.FromString("a", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Text, reader.TokenKind); Assert.AreEqual("a", reader.Text); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public void DataNamedCharacterReference3() { reader = HtmlReaderFactory.FromString("I'm ∉ I tell you", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Text, reader.TokenKind); Assert.AreEqual("I'm ∉ I tell you", reader.Text); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public void DataNamedCharacterReference2() { reader = HtmlReaderFactory.FromString("I'm ¬it; I tell you", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Text, reader.TokenKind); Assert.AreEqual("I'm ¬it; I tell you", reader.Text); Assert.IsFalse(reader.Read()); Assert.AreEqual(1, parseErrors.Count); Assert.AreEqual(1, parseErrors[0].LineNumber); Assert.AreEqual(6, parseErrors[0].LinePosition); }
public void TagUnquotedAttributeValue() { reader = HtmlReaderFactory.FromString("<a href=javascript:;>", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Tag, reader.TokenKind); Assert.AreEqual("a", reader.Name); Assert.AreEqual("javascript:;", reader.GetAttribute("href")); Assert.IsFalse(reader.SelfClosingElement); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public void TagMissingAttribute() { reader = HtmlReaderFactory.FromString("<a>", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Tag, reader.TokenKind); Assert.AreEqual("a", reader.Name); Assert.IsNull(reader.GetAttribute("href")); Assert.IsFalse(reader.SelfClosingElement); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public void GetAttributeReturnsFirstAttributeValue() { reader = HtmlReaderFactory.FromString("<img src=\"a\" src=\"b\" />", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Tag, reader.TokenKind); Assert.AreEqual("img", reader.Name); Assert.AreEqual(2, reader.AttributeCount); Assert.AreEqual("a", reader.GetAttribute("src")); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public void RcDataEmpty() { reader = HtmlReaderFactory.FromString("<title></title>", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Tag, reader.TokenKind); Assert.AreEqual("title", reader.Name); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.EndTag, reader.TokenKind); Assert.AreEqual("title", reader.Name); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public string Render() { StringBuilder sb = new StringBuilder(); sb.AppendLine(HtmlReader.Read(Constans.Header)); sb.AppendLine(HtmlReader.Read(Constans.NavLogged)); sb.AppendLine(HtmlReader.Read(Constans.Home)); int count = 1; foreach (var model in this.Model) { if (count == 3) { sb.AppendLine("</div>"); count = 1; } sb.AppendLine("<div class=\"row\""); sb.Append(model.ToString()); count++; } sb.AppendLine(Environment.NewLine); sb.AppendLine(HtmlReader.Read(Constans.HomeEnd)); sb.AppendLine(HtmlReader.Read(Constans.Footer)); return(sb.ToString()); }
public void Empty() { reader = HtmlReaderFactory.FromString("", parseErrors); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
private string Read(string html) { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(html))) { var result = ((IEnumerable <HtmlChunk>)HtmlReader.Read(stream).ToList()).ToArray(); return(string.Join(", ", result.Select(x => x.Type + ":" + x.Value).ToArray())); } }
public string Render() { StringBuilder sb = new StringBuilder(); sb.AppendLine(HtmlReader.Read(Constans.Header)); sb.AppendLine(HtmlReader.Read(Constans.NavLogged)); sb.AppendLine(HtmlReader.Read(Constans.EditGame)); sb.AppendLine(HtmlReader.Read(Constans.Footer)); return(sb.ToString()); }
static void Main(string[] args) { string path = args.Length > 0 ? args[0] : string.Empty; var htmlReader = new HtmlReader(); var html = htmlReader.Read(path); var game = GfxFactory.Create <IGfxGame>(); game.Create(1200, 800, GameWindowFlags.Default, html); game.Run(30.0); }
static void Main(string[] args) { string path = args.Length > 0 ? args[0] : string.Empty; var htmlReader = new HtmlReader(); var html = htmlReader.Read(path); var game = new TGame();; game.Create(800, 600, 0, html); game.Run(30.0); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(HtmlReader.Read(Constans.GameDetails)); sb.Replace("{trailer}", this.Trailer); sb.Replace("{description}", this.Description); sb.Replace("{price}", this.Price.ToString()); sb.Replace("{size}", this.Size.ToString()); sb.Replace("{releaseDate}", this.ReleaseDate.ToString()); return(sb.ToString()); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine(HtmlReader.Read(Constans.GameTemplate)); sb.Replace("{thumblain}", this.ImageThumblain); sb.Replace("{title}", this.Title); sb.Replace("{price}", this.Price.ToString()); sb.Replace("{size}", this.Size.ToString()); sb.Replace("{id}", this.Id.ToString()); sb.Replace("{description}", this.Description.Substring(0, 299)); return(sb.ToString()); }
public void RcDataWithCharacterReference() { reader = HtmlReaderFactory.FromString("<title>&</title><p>", parseErrors); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Tag, reader.TokenKind); Assert.AreEqual("title", reader.Name); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Text, reader.TokenKind); Assert.AreEqual("&", reader.Text); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.EndTag, reader.TokenKind); Assert.AreEqual("title", reader.Name); Assert.IsTrue(reader.Read()); Assert.AreEqual(HtmlTokenKind.Tag, reader.TokenKind); Assert.AreEqual("p", reader.Name); Assert.IsFalse(reader.Read()); Assert.AreEqual(0, parseErrors.Count); }
public List <string> ExtractTexts() { stream.Seek(0, SeekOrigin.Begin); var htmlReader = new HtmlReader(new StreamReader(stream)); var texts = new List <string>(); while (htmlReader.Read()) { if (htmlReader.TokenKind == HtmlTokenKind.Text) { texts.Add(htmlReader.Text); } } return(texts); }
public List <string> ExtractLinks() { stream.Seek(0, SeekOrigin.Begin); var htmlReader = new HtmlReader(new StreamReader(stream)); var links = new List <string>(); while (htmlReader.Read()) { if (htmlReader.TokenKind == HtmlTokenKind.Tag && htmlReader.Name == "a") { var hrefAttributeValue = htmlReader.GetAttribute("href"); if (hrefAttributeValue != null) { links.Add(hrefAttributeValue); } } } return(links); }
private void button1_Click(object sender, EventArgs e) { WebClient client = new WebClient(); html = Encoding.UTF8.GetString(client.DownloadData("http://fc.wut.edu.cn:8086/")); //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://fc.wut.edu.cn:8086/"); html = html.Substring(html.IndexOf("<html")); HtmlGrammarOptions options = new HtmlGrammarOptions(); options.HandleCharacterReferences = true; options.DecomposeCharacterReference = true; options.HandleUnfinishedTags = true; HtmlGrammar grammar = new HtmlGrammar(options); HtmlReader reader = new HtmlReader(html, grammar); while (reader.Enumerator.IsDisposed) { txtHtmlWhole.Text += reader.Enumerator.MoveNext().ToString(); } reader.Builder.TokenChaning += delegate(TokenChangingArgs args) { if (args.HasBefore) { txtHtmlWhole.Text += (args.Before.Id + " ## " + args.Before.Value + "\r\n"); } }; HtmlReader.Read(reader, null); //txtHtmlWhole.Text += reader.Status.ToString(); //AfterWork.Html.Link link = new AfterWork.Html.Link(state, category); //txtHtmlWhole.Text += reader.State.Name; //webBrowser1.DocumentCompleted += // new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted); }
public string Render() { string html = HtmlReader.Read(Constans.Login); return(html); }
public void ParseBalancedFile() { _counter.Increment(); HtmlReader.Read(TestData.BalancedHtml).Count(); }
public void ParseAttributesFile() { _counter.Increment(); HtmlReader.Read(TestData.AttributesHtml).Count(); }
public void ParseLongFile() { _counter.Increment(); HtmlReader.Read(TestData.LongHtml).Count(); }
public void ParseDeepFile() { _counter.Increment(); HtmlReader.Read(TestData.DeepHtml).Count(); }
public string Render() { string html = HtmlReader.Read(Constans.FeedSigned); return(html); }