示例#1
0
        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);
        }
示例#2
0
        public void Line_ReadParagraphStartTagOnFirstLine_ReturnsOne()
        {
            CreateReader("<p>");
            reader.Read();

            int line = reader.Line;

            Assert.AreEqual(1, line);
        }
示例#3
0
        public void AttributeValueNamedCharacterReference()
        {
            reader = HtmlReaderFactory.FromString("<a title=\"&lt;\">", parseErrors);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual("<", reader.GetAttribute("title"));

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(0, parseErrors.Count);
        }
示例#4
0
        public void DataHexCharacterReference()
        {
            reader = HtmlReaderFactory.FromString("&#x41;", 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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        public void DataNamedCharacterReference3()
        {
            reader = HtmlReaderFactory.FromString("I'm &notin; 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);
        }
示例#8
0
        public void DataNamedCharacterReference2()
        {
            reader = HtmlReaderFactory.FromString("I'm &notit; 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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        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());
        }
示例#14
0
        public void Empty()
        {
            reader = HtmlReaderFactory.FromString("", parseErrors);

            Assert.IsFalse(reader.Read());
            Assert.AreEqual(0, parseErrors.Count);
        }
示例#15
0
 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()));
     }
 }
示例#16
0
        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());
        }
示例#17
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 = GfxFactory.Create <IGfxGame>();

            game.Create(1200, 800, GameWindowFlags.Default, html);
            game.Run(30.0);
        }
示例#18
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());
        }
示例#21
0
        public void RcDataWithCharacterReference()
        {
            reader = HtmlReaderFactory.FromString("<title>&amp;</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);
        }
示例#22
0
        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);
        }
示例#23
0
        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);
        }
示例#24
0
        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);
        }
示例#25
0
        public string Render()
        {
            string html = HtmlReader.Read(Constans.Login);

            return(html);
        }
示例#26
0
 public void ParseBalancedFile()
 {
     _counter.Increment();
     HtmlReader.Read(TestData.BalancedHtml).Count();
 }
示例#27
0
 public void ParseAttributesFile()
 {
     _counter.Increment();
     HtmlReader.Read(TestData.AttributesHtml).Count();
 }
示例#28
0
 public void ParseLongFile()
 {
     _counter.Increment();
     HtmlReader.Read(TestData.LongHtml).Count();
 }
示例#29
0
 public void ParseDeepFile()
 {
     _counter.Increment();
     HtmlReader.Read(TestData.DeepHtml).Count();
 }
示例#30
0
        public string Render()
        {
            string html = HtmlReader.Read(Constans.FeedSigned);

            return(html);
        }