Ejemplo n.º 1
0
        public void AppendLink(string text, Uri uri)
        {
            Paragraph paragraph;

            if (this.Blocks.Count == 0 ||
                (paragraph = this.Blocks[this.Blocks.Count - 1] as Paragraph) == null)
            {
                paragraph = new Paragraph();
                this.Blocks.Add(paragraph);
            }

            var run = new Run {
                Text = HtmlHelp.NoHTML(text)
            };
            var link = new Hyperlink {
            };

            link.Click += new RoutedEventHandler((sender, e) =>
            {
                WebBrowserTask task = new WebBrowserTask();
                task.Uri            = uri;
                task.Show();
            });

            link.Inlines.Add(run);
            paragraph.Inlines.Add(link);
        }
Ejemplo n.º 2
0
        public void AppendText(string text)
        {
            Paragraph paragraph;

            if (this.Blocks.Count == 0 ||
                (paragraph = this.Blocks[this.Blocks.Count - 1] as Paragraph) == null)
            {
                paragraph = new Paragraph();
                this.Blocks.Add(paragraph);
            }

            paragraph.Inlines.Add(new Run {
                Text = HtmlHelp.NoHTML(text)
            });
        }
Ejemplo n.º 3
0
        private void SetColorText(string htmlFragment)
        {
            if (htmlFragment == null || htmlFragment.Length == 0)
            {
                return;
            }

            Paragraph paragraph;

            if (this.Blocks.Count == 0 ||
                (paragraph = this.Blocks[this.Blocks.Count - 1] as Paragraph) == null)
            {
                paragraph = new Paragraph();
                this.Blocks.Add(paragraph);
            }
            int nextOffset = 0;

            var regEx = new Regex(@"(\[color=#FFFFFF\](?<colortxt>.*?)\[/color\])", RegexOptions.IgnoreCase | RegexOptions.Singleline);

            foreach (Match match in regEx.Matches(htmlFragment))
            {
                if (match.Index == nextOffset)
                {
                    nextOffset = match.Index + match.Length;
                    paragraph.Inlines.Add(new Run {
                        Text = "(此处反白)->" + HtmlHelp.NoTag(match.Groups["colortxt"].Value) + "<-", Foreground = new SolidColorBrush(Colors.Red)
                    });
                }
                else if (match.Index > nextOffset)
                {
                    paragraph.Inlines.Add(new Run {
                        Text = HtmlHelp.NoTag(htmlFragment.Substring(nextOffset, match.Index - nextOffset))
                    });
                    nextOffset = match.Index + match.Length;
                    paragraph.Inlines.Add(new Run {
                        Text = "(此处反白)->" + HtmlHelp.NoTag(match.Groups["colortxt"].Value) + "<-", Foreground = new SolidColorBrush(Colors.Red)
                    });
                }
            }

            if (nextOffset < htmlFragment.Length)
            {
                paragraph.Inlines.Add(new Run {
                    Text = HtmlHelp.NoTag(htmlFragment.Substring(nextOffset))
                });
            }
        }
Ejemplo n.º 4
0
        private async Task <ObservableCollection <ACItem> > getList(ObservableCollection <ACItem> list, string url)
        {
            try
            {
                indicator.IsVisible = true;
                var request = (HttpWebRequest)WebRequest.Create(new Uri(url));
                request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";
                var response = await request.GetResponseAsync();

                var doc = new HtmlDocument();
                doc.Load(response.GetResponseStream());


                var node = getListNode(doc);
                if (node != null)
                {
                    foreach (var item in node.ChildNodes)
                    {
                        if (item.Name.Equals("div"))
                        {
                            var listtemp = new List <HtmlNode>();
                            foreach (var label in item.ChildNodes)
                            {
                                if (label.Name.Equals("a") || label.Name.Equals("div"))
                                {
                                    listtemp.Add(label);
                                }
                            }

                            ACItem acitem = new ACItem();
                            acitem.title  = listtemp[1].InnerText;
                            acitem.href   = listtemp[0].Attributes[2].Value;
                            acitem.dis    = listtemp[2].ChildNodes[3].InnerText;
                            acitem.time   = listtemp[1].Attributes[3].Value;
                            acitem.name   = HtmlHelp.NoHTML(listtemp[2].ChildNodes[1].InnerText);
                            acitem.beizhu = HtmlHelp.NoHTML(listtemp[3].InnerText);
                            list.Add(acitem);
                        }
                    }
                }
                indicator.IsVisible = false;
            }
            catch (WebException) { MessageBox.Show("网络不给力啊~"); }
            catch (Exception) { }
            indicator.IsVisible = false;
            return(list);
        }
Ejemplo n.º 5
0
        private void SetEmojiText(string htmlFragment)
        {
            if (htmlFragment == null || htmlFragment.Length == 0)
            {
                return;
            }

            this.Blocks.Clear();

            Paragraph paragraph;

            if (this.Blocks.Count == 0 ||
                (paragraph = this.Blocks[this.Blocks.Count - 1] as Paragraph) == null)
            {
                paragraph = new Paragraph();
                this.Blocks.Add(paragraph);
            }
            int nextOffset = 0;

            var regEx = new Regex(@"(\[emot=(?<emoji>.*?)/\])", RegexOptions.IgnoreCase | RegexOptions.Singleline);

            foreach (Match match in regEx.Matches(htmlFragment))
            {
                if (match.Index == nextOffset)
                {
                    nextOffset = match.Index + match.Length;
                    if (match.Groups["emoji"].Value.Split(',').Count() > 1)
                    {
                        Grid grid = new Grid();
                        grid.Background = new SolidColorBrush(Colors.White);
                        grid.Margin     = new Thickness(1, 0, 1, 0);
                        Image       image = new Image();
                        BitmapImage bi    = new BitmapImage(new Uri("/Assets/Emoji/"
                                                                    + match.Groups["emoji"].Value.Split(',')[0] + "/" + match.Groups["emoji"].Value.Split(',')[1] + ".png", UriKind.RelativeOrAbsolute));
                        image.Source = bi;
                        image.Height = 60;
                        grid.Children.Add(image);
                        InlineUIContainer container = new InlineUIContainer();
                        container.Child = grid;
                        paragraph.Inlines.Add(container);
                    }
                    else
                    {
                        this.SetAtText(HtmlHelp.NoHTML(match.Groups["emoji"].Value));
                    }
                }
                else if (match.Index > nextOffset)
                {
                    this.SetAtText(HtmlHelp.NoHTML(htmlFragment.Substring(nextOffset, match.Index - nextOffset)));
                    nextOffset = match.Index + match.Length;
                    if (match.Groups["emoji"].Value.Split(',').Count() > 1)
                    {
                        Grid grid = new Grid();
                        grid.Background = new SolidColorBrush(Colors.White);
                        grid.Margin     = new Thickness(1, 0, 1, 0);
                        Image       image = new Image();
                        BitmapImage bi    = new BitmapImage(new Uri("/Assets/Emoji/"
                                                                    + match.Groups["emoji"].Value.Split(',')[0] + "/" + match.Groups["emoji"].Value.Split(',')[1] + ".png", UriKind.RelativeOrAbsolute));
                        image.Source = bi;
                        image.Height = 60;
                        grid.Children.Add(image);
                        InlineUIContainer container = new InlineUIContainer();
                        container.Child = grid;
                        paragraph.Inlines.Add(container);
                    }
                    else
                    {
                        this.SetAtText(HtmlHelp.NoHTML(match.Groups["emoji"].Value));
                    }
                }
            }

            if (nextOffset < htmlFragment.Length)
            {
                this.SetAtText(HtmlHelp.NoHTML(htmlFragment.Substring(nextOffset)));
            }
        }