Inheritance: Inline, IInlineUIContainer
Example #1
0
 internal static void Analyse(HtmlNode node, InlineCollection container, ParsingStyle style)
 {
     if (node == null)
         return;
     foreach (var item in node.ChildNodes)
     {
         switch (item.Name)
         {
             //文本
             case "#text":
                 container.Add(new Run() { Text = item.InnerText });
                 continue;
             case "strong":
                 style = style | ParsingStyle.Bold;
                 break;
             //链接
             case "a":
                 var link = new Hyperlink();
                 ParseRelativeUrl(item.GetAttributeValue("href", ""), link, App.Current.NavigationService);
                 Analyse(item, link.Inlines, style);
                 container.Add(link);
                 continue;
             //图片
             case "img":
                 var image = new Image() { Source = new BitmapImage(new Uri(item.GetAttributeValue("src", ""))) };
                 var cont = new InlineUIContainer();
                 cont.Child = image;
                 container.Add(cont);
                 continue;
             //换行
             case "br":
                 container.Add(new LineBreak());
                 continue;
             //容器
             case "span":
             case "div":
             case "p":
                 break;
             case "b":
                 //TODO: 设置属性,是否要加红搜索显示结果
                 if(node.GetAttributeValue("class","") == "key_red")
                 {
                     Span p = new Span();
                     p.Foreground = new SolidColorBrush(Colors.Red);
                     Analyse(item, container, style);
                     continue;
                 }
                 else break;
             //非文本
             case "button":
                 continue;
             default:
                 continue;
         }
         Analyse(item, container, style);
     }
 }
 private static Inline GenerateLI(HtmlNode node)
 {
     Span s = new Span();
     InlineUIContainer iui = new InlineUIContainer();
     Ellipse ellipse = new Ellipse();
     ellipse.Fill = (SolidColorBrush)Application.Current.Resources["ApplicationForegroundThemeBrush"];
     ellipse.Width = 6;
     ellipse.Height = 6;
     ellipse.Margin = new Thickness(0, 0, 5, 2);
     iui.Child = ellipse;
     s.Inlines.Add(iui);
     HtmlNode newNode = new HtmlNode(HtmlNodeType.Text, new HtmlDocument(), 0) { InnerHtml = node.InnerText };
     AddChildren(s, newNode);
     s.Inlines.Add(new LineBreak());
     return s;
 }
Example #3
0
 private static Block GenerateTopIFrame(HtmlNode node)
 {
     try
     {
         Paragraph p = new Paragraph();
         InlineUIContainer iui = new InlineUIContainer();
         WebView ww = new WebView() { Source = new Uri(node.Attributes["src"].Value, UriKind.Absolute), Width = Int32.Parse(node.Attributes["width"].Value), Height = Int32.Parse(node.Attributes["height"].Value) };
         iui.Child = ww;
         p.Inlines.Add(iui);
         return p;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
Example #4
0
 private static Inline GenerateImage(HtmlNode node)
 {
     Span s = new Span();
     try
     {
         InlineUIContainer iui = new InlineUIContainer();
         var sourceUri = System.Net.WebUtility.HtmlDecode(node.Attributes["src"].Value);
         Image img = new Image() { Source = new BitmapImage(new Uri(sourceUri, UriKind.Absolute)) };
         img.Stretch = Stretch.Uniform;
         img.VerticalAlignment = VerticalAlignment.Top;
         img.HorizontalAlignment = HorizontalAlignment.Left;
         img.ImageOpened += img_ImageOpened;
         img.ImageFailed += img_ImageFailed;
         iui.Child = img;
         s.Inlines.Add(iui);
         s.Inlines.Add(new LineBreak());
     }
     catch (Exception ex)
     {
     }
     return s;
 }
Example #5
0
        private static Inline GenerateHyperLink(HtmlNode node)
        {
            Span s = new Span();
            InlineUIContainer iui = new InlineUIContainer();
            HyperlinkButton hb = new HyperlinkButton() { NavigateUri = new Uri(node.Attributes["href"].Value, UriKind.Absolute), Content = CleanText(node.InnerText) };

            if (node.ParentNode != null && (node.ParentNode.Name == "li" || node.ParentNode.Name == "LI"))
                hb.Style = (Style)Application.Current.Resources["RTLinkLI"];
            else if ((node.NextSibling == null || string.IsNullOrWhiteSpace(node.NextSibling.InnerText)) && (node.PreviousSibling == null || string.IsNullOrWhiteSpace(node.PreviousSibling.InnerText)))
                hb.Style = (Style)Application.Current.Resources["RTLinkOnly"];
            else
                hb.Style = (Style)Application.Current.Resources["RTLink"];

            iui.Child = hb;
            s.Inlines.Add(iui);
            return s;
        }
 public void Visit(UnorderedList unorderedList)
 {
     var uiElements = BuildChildUIList(unorderedList);
     var inlineContainer = new InlineUIContainer();
     inlineContainer.Child = new MarkdownList(false, uiElements);
     MaybeSplitForParagraph();
     _currentParagraph.Inlines.Add(inlineContainer);
 }
        public void Visit(Link link)
        {
            var inlineContainer = new InlineUIContainer();

            SnuDomCategoryVisitor categoryVisitor = new SnuDomCategoryVisitor();
            if (link.Display != null)
            {
                foreach (var item in link.Display)
                {
                    item.Accept(categoryVisitor);
                }
            }

            if (categoryVisitor.Category == MarkdownCategory.PlainText)
            {
                var plainTextVisitor = new SnuDomPlainTextVisitor();
                if (link.Display != null)
                {
                    foreach (var item in link.Display)
                        item.Accept(plainTextVisitor);
                }
                else
                    plainTextVisitor.Result = link.Url;

                inlineContainer.Child = new MarkdownLink(link.Url, plainTextVisitor.Result);
            }
            else
            {
                var fullUIVisitor = new SnuDomFullUIVisitor(_forgroundBrush);
                //cant be null in this category
                foreach (var item in link.Display)
                    item.Accept(fullUIVisitor);

                inlineContainer.Child = new MarkdownLink(link.Url, fullUIVisitor.Result);
            }

            _currentParagraph.Inlines.Add(inlineContainer);
        }
        public void Visit(Text text)
        {
            var madeRun = new Run { Text = text.Contents };
            _textLengthInCurrent += text.Contents.Length;

            if (text.Italic)
                madeRun.FontStyle = Windows.UI.Text.FontStyle.Italic;

            if (text.Bold)
                madeRun.FontWeight = FontWeights.Bold;

            if (text.HeaderSize != 0)
            {
                switch (text.HeaderSize)
                {
                    case 1:
                        madeRun.FontSize = 24;
                        break;
                    case 2:
                        madeRun.FontSize = 24;
                        madeRun.FontWeight = FontWeights.Bold;
                        madeRun.Foreground = _forgroundBrush;
                        break;
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                        madeRun.FontSize = 28;
                        madeRun.FontWeight = FontWeights.Bold;
                        break;
                }
                MaybeSplitForParagraph();
                _currentParagraph.Inlines.Add(madeRun);
                if (text.HeaderSize == 1)
                {
                    var inlineContainer = new InlineUIContainer();
                    inlineContainer.Child = new Border
                    {
                        Margin = new Thickness(0, 5, 0, 5),
                        Height = 1,
                        VerticalAlignment = VerticalAlignment.Top,
                        BorderBrush = _forgroundBrush,
                        BorderThickness = new Thickness(1),
                        MinWidth = 1800
                    };
                    _currentParagraph.Inlines.Add(inlineContainer);
                }
                else
                    _currentParagraph.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak());

            }
            else
            {
                if (_currentParagraph == null)
                {
                    _currentParagraph = new Windows.UI.Xaml.Documents.Paragraph();
                    Result.Blocks.Add(_currentParagraph);
                }
                _currentParagraph.Inlines.Add(madeRun);
            }
        }
        private static string UnorderedListXaml(HtmlNode cntnt)
        {
            if (IsFirstRun)
            {
                return ("<Paragraph TextAlignment=\"Left\"><Span FontFamily=\"rp_ul" + UlCount.ToString() + "\" /></Paragraph>");
            }
            else
            {
                InlineUIContainer ilContainer = new InlineUIContainer();
                StackPanel spUL = new StackPanel();

                //set the stapanel margin
                spUL.Margin = new Thickness(25, 0, 0, 0);

                //create a textblock for displaying the text
                System.Collections.Generic.IList<String> contentList = new System.Collections.Generic.List<String>();
                TextBlock tbItm = null;
                foreach (HtmlNode itm in cntnt.ChildNodes)
                {
                    if (itm.Name.Equals("li"))
                    {
                        tbItm = new TextBlock();
                        tbItm.Text = "« " + itm.InnerText;
                        spUL.Children.Add(tbItm);
                    }
                }
                ilContainer.Child = spUL;

                //fire the event
                OnContainerCreated("rp_ul" + UlCount.ToString(), ilContainer);

                //add the container to the control
                //HandlXamlReplacements("rp_ul" + UlCount.ToString(), ilContainer);

                return string.Empty;
            }
        }
        /// <summary>
        /// blockqoute handler
        /// </summary>
        /// <param name="cntnt"></param>
        /// <returns></returns>
        private static string BlockQuoteXaml(HtmlNode cntnt)
        {
            if (IsFirstRun)
            {
                return ("<Paragraph TextAlignment=\"Left\"><Span FontFamily=\"rp_bq" + BqCount.ToString() + "\" /></Paragraph>");
            }
            else
            {
                InlineUIContainer ilContainer = new InlineUIContainer();

                TextBlock tbItm = new TextBlock();
                tbItm.Margin = new Thickness(25, 0, 0, 0);
                tbItm.TextWrapping = TextWrapping.Wrap;
                tbItm.Text = cntnt.InnerText;

                ilContainer.Child = tbItm;

                OnContainerCreated("rp_bq" + BqCount.ToString(), ilContainer);

                return string.Empty;
            }
        }
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                var tagNameToUpper = (child as XmlElement)?.TagName?.ToUpper();

                if (!isInP
                    && !(child is XmlElement && (tagNameToUpper == "P" || tagNameToUpper == "SPAN" || tagNameToUpper == "DIV" || tagNameToUpper == "IMG")))
                {
                    var paragraph = new Paragraph();
                    parent.Add(paragraph);
                    isInP = true;
                    parent = new ParagraphTextContainer(parent, paragraph);
                }

                if (child is XmlText)
                {
                    var text = child.InnerText.Replace("\n", "").Trim();
                    if (string.IsNullOrEmpty(text))
                        continue;

                    text = text.Replace("</form>", "");
                    parent.Add(new Run { Text = System.Net.WebUtility.HtmlDecode(text), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (tagNameToUpper)
                    {
                        case "P":
                        case "DIV":
                        case "SPAN":
                            if(tagNameToUpper == "DIV")
                            {
                                var classVal = e.Attributes.FirstOrDefault(a => a.NodeName == "class")?.NodeValue?.ToString() ?? "";
                                
                                if(classVal.Contains("open-list-comments") ||
                                   classVal.Contains("open-list-footer") ||
                                   classVal.Contains("modal-body"))
                                {
                                    return;
                                }
                            }

                            if (isInP)
                            {
                                if (tagNameToUpper == "P")
                                    parent.Add(new LineBreak());
                                ParseElement(e, parent);
                            }
                            else
                            {
                                var paragraph = new Paragraph();
                                parent.Add(paragraph);
                                isInP = true;
                                ParseElement(e, new ParagraphTextContainer(parent, paragraph));
                                isInP = false;
                            }
                            break;
                        case "B":
                        case "STRONG":
                        case "H1":
                        case "H2":
                        case "H3":
                        case "H4":
                        case "H5":
                        case "H6":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(parent, bold));
                            break;
                        case "I":
                        case "EM":
                            var italic = new Italic();
                            parent.Add(italic);
                            ParseElement(e, new SpanTextContainer(parent, italic));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(parent, underline));
                            break;
                        case "A":
                            var url = e.Attributes.FirstOrDefault(a => a.NodeName == "href")?.NodeValue;
                            Uri uri;
                            if (url != null && Uri.TryCreate(url.ToString(), UriKind.Absolute, out uri))
                            {
                                var link = new Hyperlink();
                                link.NavigateUri = uri;
                                parent.Add(link);
                                ParseElement(e, new SpanTextContainer(parent, link));
                            }
                            else
                            {
                                ParseElement(e, parent);
                            }

                            break;
                        case "BR":
                            parent.Add(new LineBreak());
                            break;
                        case "IMG":
                            var src = e.Attributes.FirstOrDefault(a => a.NodeName == "src")?.NodeValue;
                            Uri srcUri;
                            if (src != null && Uri.TryCreate(src.ToString(), UriKind.Absolute, out srcUri))
                            {
                                var img = new InlineUIContainer
                                {
                                    Child = new Windows.UI.Xaml.Controls.Image()
                                    {
                                        Source = new BitmapImage(srcUri)
                                    }
                                };

                                parent.AddToParentParagraph(img);
                            }
                            break;
                    }
                }
            }
        }
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                if (child is Windows.Data.Xml.Dom.XmlText)
                {
                    if (string.IsNullOrEmpty(child.InnerText) ||
                        child.InnerText == "\n")
                    {
                        continue;
                    }

                    parent.Add(new Run { Text = child.InnerText.Trim(new char[] {'\n'}) });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (e.TagName.ToUpper())
                    {
                        case "P":
                            var paragraph = new Paragraph();
                            parent.Add(paragraph);
                            ParseElement(e, new ParagraphTextContainer(paragraph));
                            break;
                        case "STRONG":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(bold));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(underline));
                            break;
                        case "A":
                            var inlineElt = new InlineUIContainer();
                            var hyperlink = new HyperlinkButton();
                            inlineElt.Child = hyperlink;
                            hyperlink.Style = (Style)App.Current.Resources["HyperlinkButtonStyle"];
                            hyperlink.Content = e.InnerText;
                            hyperlink.Click += delegate(object sender, RoutedEventArgs eventArgs)
                            {
                                string uriString = e.GetAttribute("href");
                                Messenger.Default.Send<LinkClickedMessage>(new LinkClickedMessage()
                                {
                                    UriToNavigate = uriString
                                });
                            };
                            parent.Add(inlineElt);
                            //ParseElement(e, parent);
                            break;
                        case "BR":
                                parent.Add(new LineBreak());
                            break;
                    }
                }

            }
        }
        /// <summary>
        /// Renders a superscript element.
        /// </summary>
        /// <param name="inlineCollection"> The list to add to. </param>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="parent"> The container element. </param>
        /// <param name="context"> Persistent state. </param>
        private void RenderSuperscriptRun(InlineCollection inlineCollection, SuperscriptTextInline element, TextElement parent, RenderContext context)
        {
            // Le <sigh>, InlineUIContainers are not allowed within hyperlinks.
            if (context.WithinHyperlink)
            {
                RenderInlineChildren(inlineCollection, element.Inlines, parent, context);
                return;
            }

            var paragraph = new Paragraph();
            paragraph.FontSize = parent.FontSize * 0.8;
            paragraph.FontFamily = parent.FontFamily;
            paragraph.FontStyle = parent.FontStyle;
            paragraph.FontWeight = parent.FontWeight;
            RenderInlineChildren(paragraph.Inlines, element.Inlines, paragraph, context);

            var richTextBlock = CreateOrReuseRichTextBlock(null, context);
            richTextBlock.Blocks.Add(paragraph);

            var border = new Border();
            border.Padding = new Thickness(0, 0, 0, paragraph.FontSize * 0.2);
            border.Child = richTextBlock;

            var inlineUIContainer = new InlineUIContainer();
            inlineUIContainer.Child = border;

            // Add it to the current inlines
            inlineCollection.Add(inlineUIContainer);
        }
Example #14
0
        private Paragraph ParseHorizontalRuleText(Paragraph currentPar, string markdown, ref int markdownPos)
        {
            // Find the next ending
            int currentParaEnding = FindNextCloestNewLineOrReturn(markdown, markdownPos);

            // Find where the list begins
            int horzStart = markdown.IndexOf('*', currentParaEnding);

            // Find the end
            int horzEnd = horzStart;
            while (markdown.Length > horzEnd)
            {
                if (markdown[horzEnd] != '*')
                {
                    break;
                }
                horzEnd++;
            }

            // Take any text that is before the quote and put in the paragraph.
            if (currentParaEnding > markdownPos)
            {
                Run preText = new Run();
                preText.Text = markdown.Substring(markdownPos, currentParaEnding - markdownPos);
                currentPar.Inlines.Add(preText);
            }

            // This is going to be weird. To make this work we need to make a UI element
            // and fill it with text to make it stretch. If we don't fill it with text I can't
            // make it stretch the width of the box, so for now this is an "ok" hack.
            InlineUIContainer contianer = new InlineUIContainer();
            Grid grid = new Grid();
            grid.Height = 2;
            grid.Background = new SolidColorBrush(Color.FromArgb(255, 153, 153, 153));

            // Add the expanding text block.
            TextBlock magicExpandingTextBlock = new TextBlock();
            magicExpandingTextBlock.Foreground = new SolidColorBrush(Color.FromArgb(255, 153, 153, 153));
            magicExpandingTextBlock.Text = "This is Quinn writing magic text. You will never see this. Like a ghost! I love Marilyn Welniak! This needs to be really long! RRRRREEEEEAAAAALLLLYYYYY LLLOOOONNNGGGG. This is Quinn writing magic text. You will never see this. Like a ghost! I love Marilyn Welniak! This needs to be really long! RRRRREEEEEAAAAALLLLYYYYY LLLOOOONNNGGGG";
            grid.Children.Add(magicExpandingTextBlock);

            // Add the grid.
            contianer.Child = grid;

            // Make the new horizontal rule paragraph
            Paragraph horzPara = new Paragraph();
            horzPara.Margin = new Thickness(0, 12, 0, 12);
            horzPara.Inlines.Add(contianer);

            // Set the markdownPos
            markdownPos = horzEnd;

            return horzPara;
        }
Example #15
0
        // 依存関係プロパティに値がセットされたときに呼び出されるメソッド
        private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBlock block = new RichTextBlock();
            Tweet tweet = e.NewValue as Tweet;
            Binding detailCommandBinding = new Binding { Path = new PropertyPath("TweetDetailCommand") };

            Binding userDetailCommandBinding = new Binding { Path = new PropertyPath("UserDetailCommand") };

            Binding searchCommandBinding = new Binding() { Path = new PropertyPath("SearchCommand") };

            Binding browseCommandBinding = new Binding() { Path = new PropertyPath("BrowseCommand") };

            Binding previewImageCommandBinding = new Binding() { Path = new PropertyPath("ImagePreviewCommand") };



                SolidColorBrush runForeGround = Application.Current.Resources["ForegroundBrush"] as SolidColorBrush;
                FontFamily tweetFontFamily = Application.Current.Resources["MainFontFamily"] as FontFamily;
                double fontSize = (double)Application.Current.Resources["TimelineFontSize"];
                if (tweet != null)
                {



                    if (tweet.retweeted_status != null)
                    {
                        tweet = tweet.retweeted_status;
                    }

                    
                    Paragraph para = new Paragraph();

                    List<EntitieBase> entities = new List<EntitieBase>();
                    if (tweet.entities != null)
                    {

                        if (tweet.entities.user_mentions != null)
                        {
                            entities.AddRange(tweet.entities.user_mentions);
                        }
                        if (tweet.entities.urls != null)
                        {
                            entities.AddRange(tweet.entities.urls);
                        }
                        if (tweet.entities.hashtags != null)
                        {
                            entities.AddRange(tweet.entities.hashtags);
                        }
                        if (tweet.entities.media != null)
                        {
                            entities.AddRange(tweet.entities.media);
                        }
                    }


                    try
                    {
                        if (tweet.entities != null && entities.Count > 0)
                        {

                            entities.OrderBy(q => q.indices[0]);
                            string back = "";
                            int seek = 0;


                            foreach (EntitieBase entitiy in entities)
                            {

                                int start = entitiy.indices[0];
                                int end = entitiy.indices[1];
                                StringInfo infoText = new StringInfo(tweet.text);
                                back = tweet.text.SubStringByTextElements(end, infoText.LengthInTextElements - end);
                                string front = tweet.text.SubStringByTextElements(seek, start - seek);

                                para.Inlines.Add(new Run { Text = front, Foreground = runForeGround, FontSize = fontSize });
                                var link = new HyperlinkButton();
                                link.Padding = new Thickness(0);
                                // link.Foreground = Application.Current.Resources["AppThemeBrush"] as SolidColorBrush;
                                link.Style = Application.Current.Resources["NeuroniaTimelineHyperlinkButtonStyle"] as Style;
                                link.FontSize = fontSize;

                                var uiContainer = new InlineUIContainer();

                                if (entitiy is UserMention)
                                {
                                    var en = entitiy as UserMention;

                                    link.Content = "@" + en.screen_name;
                                    uiContainer.Child = link;
                                    link.CommandParameter = en.screen_name;
                                    link.SetBinding(HyperlinkButton.CommandProperty, userDetailCommandBinding);
                                }
                                else if (entitiy is TweetUrl)
                                {
                                    var en = entitiy as TweetUrl;
                                    link.Content = en.display_url;
                                    uiContainer.Child = link;
                                    link.CommandParameter = en.url;
                                    link.SetBinding(HyperlinkButton.CommandProperty, browseCommandBinding);

                                }
                                else if (entitiy is HashTag)
                                {
                                    var en = entitiy as HashTag;
                                    link.Content = "#" + en.text;
                                    uiContainer.Child = link;
                                    link.CommandParameter = "#" + en.text;
                                    link.SetBinding(HyperlinkButton.CommandProperty, searchCommandBinding);
                                }
                                else if (entitiy is TweetMedia)
                                {
                                    var en = entitiy as TweetMedia;

                                    Button btn = new Button();
                                    btn.Width = (double)Application.Current.Resources["previewImageWidth"];

                                    //btn.HorizontalAlignment = HorizontalAlignment.Stretch;
                                    btn.Height = (double)Application.Current.Resources["previewImageHeight"];
                                    btn.Style = Application.Current.Resources["NeuroniaTimelineImageButtonStyle"] as Style;
                                    var imageBrush = new ImageBrush() { ImageSource = new BitmapImage(new Uri(en.media_url)), Stretch = Stretch.UniformToFill };
                                    btn.Background = imageBrush;
                                    btn.CommandParameter = en;
                                    btn.SetBinding(Button.CommandProperty, previewImageCommandBinding);
                                    var flyout = Application.Current.Resources["ImagePreviewFlyout"] as Flyout;
                                    flyout.Placement = FlyoutPlacementMode.Top;

                                    var grid = (flyout.Content as Grid);

                                    btn.Flyout = flyout;
                                    uiContainer.Child = btn;

                                    para.Inlines.Add(new LineBreak());
                                }
                                para.Inlines.Add(uiContainer);
                                seek = end;
                            }

                            para.Inlines.Add(new Run { Text = back, Foreground = runForeGround, FontFamily = tweetFontFamily, FontSize = fontSize });


                        }
                        else
                        {
                            para.Inlines.Add(new Run { Text = tweet.text, Foreground = runForeGround, FontFamily = tweetFontFamily, FontSize = fontSize });
                        }

                        block.Blocks.Add(para);
                    }
                    catch (Exception ee)
                    {
                        //Debug.WriteLine(value.ToString());
                    }

                    
                }
            

            (d as ContentControl).Content = block;

            
            
        }
        private static Inline GenerateHyperLink(HtmlNode node)
        {
            Span s = new Span();
            InlineUIContainer iui = new InlineUIContainer();

            Debug.WriteLine(node.Attributes["href"].Value);
            Hyperlink hb;
            string lk = node.Attributes["href"].Value;
            if (!lk.Contains("http"))
            {
                lk = string.Format("http://ifixit.com/{0}", lk);
            }
            hb = new Hyperlink() { NavigateUri = new Uri(lk, UriKind.RelativeOrAbsolute) };

          
            hb.Inlines.Add(GenerateSpan(node," "));

            //if (node.ParentNode != null && (node.ParentNode.Name == "li" || node.ParentNode.Name == "LI"))
            //    hb.Style = (Style)Application.Current.Resources["RTLinkLI"];
            //else if ((node.NextSibling == null || string.IsNullOrWhiteSpace(node.NextSibling.InnerText)) && (node.PreviousSibling == null || string.IsNullOrWhiteSpace(node.PreviousSibling.InnerText)))
            //    hb.Style = (Style)Application.Current.Resources["RTLinkOnly"];
            //else
            //    hb.Style = (Style)Application.Current.Resources["RTLink"];

            //  iui.Child = hb;

            s.Inlines.Add(hb);
           
            return s;
        }
Example #17
0
        public static void FixUpXaml(Paragraph paragraph)
        {
            for(int i = 0; i < paragraph.Inlines.Count; i++)
            {
                Inline inline = paragraph.Inlines[i];
                ImageInline imageInline;
                if (TryCreate(inline, out imageInline))
                {
                    BitmapImage bi = new BitmapImage(new Uri(imageInline.FilePath));
                    Image image = new Image();
                    image.Source = bi;
                    image.Stretch = Stretch.Uniform;
                    InlineUIContainer container = new InlineUIContainer();
                    image.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
                    image.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;
                    image.Stretch = Stretch.Uniform;
                    container.Child = image;
                    paragraph.Inlines[i] = container;

                    // if this is an image only paragraph. Center it
                    if (paragraph.Inlines.Count == 1)
                    {
                        paragraph.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
                    }
                }
            }
        }
        private static string HtmlTableXaml(HtmlNode cntnt)
        {
            if (IsFirstRun)
            {
                return ("<Paragraph TextAlignment=\"Left\"><Span FontFamily=\"rp_tb" + TbCount.ToString() + "\" /></Paragraph>");
            }
            else
            {
                Grid tableGrid = null;
                //var grdWidth = CalulateItemWidth(cntnt, RTB.ActualWidth);

                IList<HtmlNode> rows =
                   (from tblNode in cntnt.ChildNodes
                    where (tblNode.Name.ToLower().Equals("tr"))
                    select tblNode).ToList();

                //CREATE Grid rows and cols
                var trNode = rows[0];
                int colCount =
                      (from tdNode in trNode.ChildNodes
                       where (tdNode.Name.ToLower().Equals("td"))
                       select tdNode).Count<HtmlNode>();

                if (rows.Count > 0 && colCount > 0)
                {
                    tableGrid = new Grid();
                    //if (grdWidth > 0)
                    //    tableGrid.Width = grdWidth;
                    //set up rows
                    for (int ictr = 0; ictr < rows.Count; ictr++)
                    {
                        tableGrid.RowDefinitions.Add(new RowDefinition());
                    }

                    //setup cols
                    for (int jctr = 0; jctr < colCount; jctr++)
                    {
                        Double wdth = CalulateItemWidth(trNode.ChildNodes[jctr], tableGrid.Width);

                        if (wdth > 0)
                            tableGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(wdth) });
                        else
                            tableGrid.ColumnDefinitions.Add(new ColumnDefinition());
                    }
                }


                if (rows.Count > 0 && colCount > 0)
                {
                    for (int trCtr = 0; trCtr < rows.Count; trCtr++)
                    {
                        IList<HtmlNode> cols = (from tdNode in rows[trCtr].ChildNodes
                                                where (tdNode.Name.ToLower().Equals("td"))
                                                select tdNode).ToList();
                        for (int tdCtr = 0; tdCtr < cols.Count; tdCtr++)
                        {
                            var tbcnt = new TextBlock {Text = cols[tdCtr].InnerText};

                            tbcnt.SetValue(Grid.RowProperty, trCtr);
                            tbcnt.SetValue(Grid.ColumnProperty, tdCtr);

                            tableGrid.Children.Add(tbcnt);
                        }
                        cols = null;
                    }
                }


                var ilContainer = new InlineUIContainer {Child = tableGrid};

                //fire the event
                OnContainerCreated("rp_tb" + TbCount.ToString(), ilContainer);

                return string.Empty;
            }
        }
 public void Visit(HorizontalRule horizontalRule)
 {
     var inlineContainer = new InlineUIContainer();
     inlineContainer.Child = new Border
     {
         Margin = new Thickness(0, 5, 0, 5),
         Height = 2,
         VerticalAlignment = VerticalAlignment.Top,
         BorderBrush = _forgroundBrush,
         BorderThickness = new Thickness(2),
         MinWidth = 1800
     };
     MaybeSplitForParagraph();
     _currentParagraph.Inlines.Add(inlineContainer);
 }
 /// <summary>
 /// this method fires the container created event.
 /// </summary>
 /// <param name="spanId"></param>
 /// <param name="ilContainer"></param>
 private static void OnContainerCreated(string spanId, InlineUIContainer ilContainer)
 {
     ContainerCreated(new ContainerEvtArgs {SpanId = spanId, Container = ilContainer});
 }
        public void Visit(Quote code)
        {
            var inlineContainer = new InlineUIContainer();

            SnuDomCategoryVisitor categoryVisitor = new SnuDomCategoryVisitor();

            foreach (var item in code)
            {
                item.Accept(categoryVisitor);
            }


            if (categoryVisitor.Category == MarkdownCategory.PlainText && code.Count() == 1)
            {
                var plainTextVisitor = new SnuDomPlainTextVisitor();

                foreach (var item in code)
                    item.Accept(plainTextVisitor);


                inlineContainer.Child = new MarkdownQuote(plainTextVisitor.Result);
            }
            else
            {
                var fullUIVisitor = new SnuDomFullUIVisitor(_forgroundBrush);
                //cant be null in this category
                foreach (var item in code)
                    item.Accept(fullUIVisitor);

                inlineContainer.Child = new MarkdownQuote(fullUIVisitor.Result);
            }

            if (_currentParagraph == null)
            {
                MaybeSplitForParagraph();
            }
            else
            {
                _currentParagraph.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak());
            }

            _currentParagraph.Inlines.Add(inlineContainer);
            _currentParagraph.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak());
        }
 /// <summary>
 /// This function adds content to the blocks collection of the RichTextBlock passed into the function.      
 /// </summary>
 /// <param name="rtbl">last rich text block</param>
 private RichTextBlock AddContentToRTBl(RichTextBlock rtbl)
 {
     InlineUIContainer container = new InlineUIContainer();
     container.Child = image;
     Paragraph paragraph = new Paragraph();
     paragraph.Inlines.Add(container);
     rtbl.Blocks.Add(paragraph);
     return rtbl;
 }
        public void Visit(Table table)
        {
            var headerUIElements = BuildChildUIList(table.Headers);
            List<IEnumerable<UIElement>> tableBody = new List<IEnumerable<UIElement>>();
            foreach (var row in table.Rows)
            {
                tableBody.Add(BuildChildUIList(row.Columns));
            }
            var inlineContainer = new InlineUIContainer();
            inlineContainer.Child = new MarkdownTable(headerUIElements, tableBody);

            if (_currentParagraph == null)
            {
                MaybeSplitForParagraph();
            }
            else
            {
                _currentParagraph.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak());
            }

            _currentParagraph.Inlines.Add(inlineContainer);
            _currentParagraph.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak());
        }
Example #24
0
        private void LoadData()
        {
            var from = (IDictionary<string, object>)posts["from"];

            InlineUIContainer uiContainer = new InlineUIContainer();
            uiContainer.Child = new UserLinks((String)from["name"], -4);
            Story.Inlines.Add(uiContainer);

            string profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", (String)from["id"], "square", _fb.AccessToken);
            UserPic.Source = new BitmapImage(new Uri(profilePictureUrl));
            
            String storytxt = "";
            String story_tag = "";
            dynamic selected_tagDic = null;
            String message = "";
            int message_tagsCount = 0;
            try
            {
                storytxt = (String)posts["story"];
            }
            catch (Exception e) { }

            try
            {
                if (((String)posts["type"]).Equals("link"))
                {
                    var application = (IDictionary<string, object>)posts["application"];
                    if (((String)application["namespace"]).Equals("likes"))
                    {
                        storytxt = " likes a link.";
                    }
                }
            }
            catch (Exception e) { }
            IDictionary<string, object> message_tagsDic = null;
            try
            {
                message_tagsDic = (IDictionary<string, object>)posts["message_tags"];
            }
            catch (Exception e) { }

            try
            {
                var story_tagsDic = (IDictionary<string, object>)posts["story_tags"];
                var story_tagsSecondEl = (IEnumerable<object>)story_tagsDic.ElementAt(1).Value;
                var selected_tag = story_tagsSecondEl.ElementAt(0);
                selected_tagDic = (IDictionary<string, object>)selected_tag;

                story_tag = (String)selected_tagDic["name"]; ;
            }
            catch (Exception e) { }

            try { message = (String)posts["message"]; }
            catch (Exception e) { }

            try
            {
                var message_tagsDicForCount = (IDictionary<string, object>)posts["message_tags"];
                message_tagsCount = message_tagsDicForCount.Count;
            }
            catch (Exception e) { }

            Run pText = new Run();
            //pText.Foreground = new SolidColorBrush(Color.FromArgb(255, 129,129,129));
            pText.Text = storytxt.Replace((String)from["name"], "");
            Story.Inlines.Add(pText);

            if (!story_tag.Equals(""))
            {
                String[] storyTextSplit = new String[] { storytxt.Substring(0, (int)selected_tagDic["offset"]), storytxt.Substring((int)selected_tagDic["offset"] + story_tag.Length) };
                
                pText.Text = storyTextSplit[0].Replace((String)from["name"], "");
                uiContainer = new InlineUIContainer();
                uiContainer.Child = new UserLinks(story_tag, false, -4);
                Story.Inlines.Add(uiContainer);
                pText = new Run();
                pText.Text = storyTextSplit.Last();
                Story.Inlines.Add(pText);
            }

            if (message_tagsDic == null)
            {
                Run r = new Run();
                r.Text = message;
                Message.Inlines.Add(r);
            }
            else
            {
                String[] modMessage = new String[]{message};
                Run r;
                int offset = 0;
                for (int i = 0; i < message_tagsDic.Count; i++)
                {
                    var message_tagEl = (IEnumerable<object>)message_tagsDic.ElementAt(i).Value;
                    dynamic message_selTag = message_tagEl.ElementAt(0);
                    message_selTag = (IDictionary<string, object>)message_selTag;
                    String message_tagName = (String)message_selTag["name"];

                    modMessage = new String[] { modMessage[0].Substring(0, (int)message_selTag["offset"]-offset), modMessage[0].Substring((int)message_selTag["offset"] - offset + message_tagName.Length) };
                    offset = message_tagName.Length + (int)message_selTag["offset"];

                    r = new Run();
                    r.Text = modMessage[0];
                    Message.Inlines.Add(r);

                    uiContainer = new InlineUIContainer();
                    uiContainer.Child = new UserLinks(message_tagName, false, -3);
                    Message.Inlines.Add(uiContainer);

                    modMessage = new String[] { modMessage[1] };
                }
                r = new Run();
                r.Text = modMessage[0];
                Message.Inlines.Add(r);
            }

            if (((String)posts["type"]).Equals("photo"))
            {
                ImagePost image = new ImagePost();

                string photoFormat = string.Format("https://graph.facebook.com/{0}/picture?access_token={1}", posts["object_id"], _fb.AccessToken);

                BitmapImage photo = new BitmapImage(new Uri(photoFormat));

                image.postImage.Source = photo;
                StatusArea.Children.Insert(StatusArea.Children.Count()-1, image);
            }

            statusControls = new StatusControls(posts, _fbSession);
            StatusControlSection.Children.Add(statusControls);
        }
Example #25
0
 private static Inline GenerateIFrame(HtmlNode node)
 {
     try
     {
         Span s = new Span();
         s.Inlines.Add(new LineBreak());
         InlineUIContainer iui = new InlineUIContainer();
         WebView ww = new WebView() { Source = new Uri(node.Attributes["src"].Value, UriKind.Absolute), Width = Int32.Parse(node.Attributes["width"].Value), Height = Int32.Parse(node.Attributes["height"].Value) };
         iui.Child = ww;
         s.Inlines.Add(iui);
         s.Inlines.Add(new LineBreak());
         return s;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
        /// <summary>
        ///     This function adds content to the blocks collection of the RichTextBlock passed into the function.
        /// </summary>
        /// <param name="rtbl">last rich text block</param>
        private RichTextBlock AddContentToRTBl(RichTextBlock rtbl)
        {
            var container = new InlineUIContainer();
            container.Child = image;
            var paragraph = new Paragraph();
            paragraph.Inlines.Add(container);
            //contentView.Visibility = Visibility.Collapsed;

            //// Create a Run and give it content
            //Run run = new Run();
            //run.Text = Reb.Text;
            //// Create a paragraph, set it's font size, add the run to the paragraph's inline collection
            //Paragraph para = new Paragraph();
            //para.FontSize = 42;
            //para.Inlines.Add(run);
            //// Add the paragraph to the blocks collection of the RichTextBlock
            rtbl.Blocks.Add(paragraph);
            return rtbl;
        }
Example #27
0
 private static Inline GenerateLI(HtmlNode node)
 {
     Span s = new Span();
     InlineUIContainer iui = new InlineUIContainer();
     Ellipse ellipse = new Ellipse();
     ellipse.Fill = new SolidColorBrush(Colors.Black);
     ellipse.Width = 6;
     ellipse.Height = 6;
     ellipse.Margin = new Thickness(-30, 0, 0, 1);
     iui.Child = ellipse;
     s.Inlines.Add(iui);
     AddChildren(s, node);
     s.Inlines.Add(new LineBreak());
     return s;
 }
        //private void outp(Paragraph p) 
        //{
        //    var idx = rtbConsole.Blocks.Count - blankLines; // ignore blank line at end
        //    rtbConsole.Blocks.Insert(idx, p);
        //    CauseScroll();
        //}

        private Inline createRun(string text)
        {
            if (String.IsNullOrEmpty(text))
                return null;

            var ctl = getFormattedText(text);
            if (ctl is Inline)
                return (Inline)ctl;
            else if (ctl is UIElement)
            {
                var result = new InlineUIContainer();
                result.Child = (UIElement)ctl;
                return result;
            }
            return null;
        }
        private void UpdateContentsView(IEnumerable<LineViewModel> lines)
        {
            Uri severBaseUri = LightKindomHtmlClient.SeverBaseUri;
            ContentTextBlock.Blocks.Clear();
            bool prevLineBreakFlag = false;
            foreach (var line in lines)
            {
                var para = new Paragraph();
                para.SetValue(ParagrahViewModelProperty, line);
                if (!line.IsImage || line.Content == null)
                {
                    //if (line.HasComments)
                    //	para.Inlines.Add(new InlineUIContainer
                    //	{
                    //		Child = new SymbolIcon { Symbol = Symbol.Message },
                    //		Foreground = (SolidColorBrush)App.Current.Resources["AppAcentBrush"]
                    //	});
                    var run = new Run { Text = line.Content };
                    para.Inlines.Add(new Run { Text = CommentIndicator, FontFamily = SegoeUISymbolFontFamily, Foreground = TransparentBrush });
                    para.Inlines.Add(run);
                    //para.TextIndent = ContentTextBlock.FontSize * 1;
                    prevLineBreakFlag = true;
                    para.Margin = new Thickness(0, 0, 0, 10);
                }
                else
                {
                    //para.LineHeight = 2;
                    Size padding = new Size(ContentTextBlock.Padding.Left + ContentTextBlock.Padding.Right, ContentTextBlock.Padding.Top + ContentTextBlock.Padding.Bottom);
                    //bitmap.DownloadProgress +=
                    //var img = new Image
                    //{
                    //	Source = bitmap,
                    //	//MaxWidth = ContentColumns.ColumnWidth - padding.Width - 1,
                    //	//Height = ContentColumns.ColumnHeight - padding.Height - PictureMargin,
                    //	HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch,
                    //	VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch,
                    //	Stretch = Stretch.Uniform,
                    //};
                    //img.DataContext = img;
                    //Flyout.SetAttachedFlyout(img, this.Resources["ImagePreviewFlyout"] as Flyout);
                    //img.Tapped += Illustration_Tapped;
                    //GetLocalImageAsync(new Uri(severBaseUri, line.Content)).ContinueWith(async (task) =>
                    //{
                    //	await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,()=>{
                    //		if (task.IsFaulted || task.Result == null)
                    //		{
                    //			img.Source = new BitmapImage(new Uri(severBaseUri, line.Content));
                    //		}
                    //		else
                    //		{
                    //			var localUri = task.Result;
                    //			img.Source = new BitmapImage(localUri);
                    //		}
                    //	});
                    //});


                    //var illustration = new Border
                    //{
                    //	HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch,
                    //	VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch,
                    //	Width = ContentColumns.ColumnWidth - padding.Width - 1,
                    //	Height = ContentColumns.ColumnHeight - padding.Height - PictureMargin,
                    //	Background = null,
                    //	BorderBrush = null,
                    //	Child = img,
                    //};

                    var illustration = LineViewCCGTemplate.LoadContent() as IllustrationView;
                    illustration.DataContext = line;
                    illustration.Width = ContentColumns.ColumnWidth - padding.Width - 1;
                    illustration.Height = ContentColumns.ColumnHeight - padding.Height - PictureMargin;
                    illustration.LoadIllustrationLine(line);
                    //LoadItemIllustation(illustration, line);
                    (illustration.FindName("ImageContent") as Image).SizeChanged += Image_SizeChanged;
                    //var bitmap = (illustration.GetFirstDescendantOfType<Image>().Source as BitmapImage);
                    //var pb = illustration.GetFirstDescendantOfType<ProgressBar>();
                    //bitmap.SetValue(BitmapLoadingIndicatorProperty, pb);

                    var inlineImg = new InlineUIContainer
                    {
                        Child = illustration // img
                    };

                    //inlineImg.FontSize = 620;
                    para.TextAlignment = TextAlignment.Center;
                    if (prevLineBreakFlag)
                    {
                        para.Inlines.Add(new Run { Text = "\n" });
                        illustration.Margin = new Thickness(0, 5, 0, 0);
                        //img.Margin = new Thickness(0, 5, 0, 0);
                    }
                    else
                    {
                        para.Inlines.Add(new Run { Text = " \n", FontSize = 5 });
                    }
                    para.Inlines.Add(inlineImg);

                    prevLineBreakFlag = false;
                }
                ContentTextBlock.Blocks.Add(para);
            }
            var ptr = ContentTextBlock.ContentStart;
            //ContentColumns.Measure(new Size(ContentScrollViewer.Height, double.PositiveInfinity));
            //ContentColumns.Children.Count;
            RichTextColumns.ResetOverflowLayout(ContentColumns, null);
        }
        private static List<Inline> CreateInlineCollection(string newValue)
        {
            var inlines = new List<Inline>();
            bool bold = false;
            bool list_item = false;
            bool unordered_list = false;
            bool ordered_list = false;
            string href = "";
            int ordered_number = -1;
            int linebreak_count = 0;
            var splits = Regex.Split(newValue, htmlLineBreakRegex, RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
            foreach (var line in splits)
            {
                if (string.IsNullOrWhiteSpace(line)) continue;
                var line_lowercase = line.ToLower();
                if (IsHtmlTag(line_lowercase))
                {
                    switch (line_lowercase)
                    {
                        case "</div>":
                        case "</p>":
                        case "<br/>":
                        case "<br />":
                        case "<br>":
                            if (!ordered_list && !unordered_list)
                                WriteLineBreak(inlines, ref linebreak_count);
                            break;
                        case "<bold>":
                        case "<b>":
                            bold = true;
                            break;
                        case "</bold>":
                        case "</b>":
                            bold = false;
                            break;
                        case "<ul>":
                            WriteLineBreak(inlines, ref linebreak_count);
                            unordered_list = true;
                            break;
                        case "</ul>":
                            unordered_list = false;
                            break;
                        case "<ol>":
                            WriteLineBreak(inlines, ref linebreak_count);
                            ordered_list = true;
                            ordered_number = 1;
                            break;
                        case "</ol>":
                            ordered_list = false;
                            ordered_number = -1;
                            break;
                        case "<li>":
                            list_item = true;
                            break;
                        case "</li>":
                            list_item = false;
                            WriteLineBreak(inlines, ref linebreak_count);
                            break;
                        case "</a>":
                            href = "";
                            break;
                    }
                }

                if (line_lowercase == "<p>" || (line_lowercase.StartsWith("<p ") && line_lowercase.EndsWith(">")))
                {
                    if (!ordered_list && !unordered_list)
                        WriteLineBreak(inlines, ref linebreak_count);
                }

                if (line_lowercase.StartsWith("<a ") && line_lowercase.Contains("href="))
                {
                    char quote = line_lowercase.Contains("href='") ? '\'' : '"';
                    int start_index = line_lowercase.IndexOf(string.Format("href={0}", quote)) + 6;
                    int end_index = line_lowercase.IndexOf(string.Format("{0}", quote), start_index);
                    href = line.Substring(start_index, end_index - start_index);
                }

                if (line_lowercase.StartsWith("<img") && line_lowercase.Contains("src='"))
                {
                    int start_index = line_lowercase.IndexOf("src='") + 5;
                    int end_index = line.IndexOf("'", start_index);
                    string src = line.Substring(start_index, end_index - start_index);

                    var image = new Image() { Source = new BitmapImage(new Uri(src, UriKind.Absolute)) };
                    image.Stretch = Stretch.None;

                    var inline_ui_container = new InlineUIContainer();
                    inline_ui_container.Child = image;

                    inlines.Add(inline_ui_container);
                    WriteLineBreak(inlines, ref linebreak_count);
                    WriteLineBreak(inlines, ref linebreak_count);
                }

                string text = Regex.Replace(line, htmlStripperRegex, string.Empty);
                Regex regex = new Regex(@"[ ]{2,}", RegexOptions.None);
                if (!string.IsNullOrWhiteSpace(text))
                {
                    text = regex.Replace(text, @" "); //Remove multiple spaces
                    text = text.Replace("&quot;", "\""); //Unencode quotes
                    text = text.Replace("&nbsp;", " "); //Unencode spaces
                    var run = new Run() { Text = text };

                    if (bold)
                        run.FontWeight = FontWeights.SemiBold;

                    if (unordered_list && list_item)
                    {
                        run.Text = run.Text.Insert(0, "•  ");
                        list_item = false;
                    }

                    if (ordered_list && list_item)
                    {
                        run.Text = run.Text.Insert(0, string.Format("{0}.  ", ordered_number++));
                        list_item = false;
                    }

                    if (!string.IsNullOrEmpty(href))
                    {
                        int pos = 0;
                        foreach (var str in text.Split(new char[] { ' ', '/' }))
                        {
                            var word = str;
                            pos += word.Length;
                            if (pos < text.Length)
                            {
                                word += text[pos];
                                pos++;
                            }
                            var hyperlink = new HyperlinkButton();
                            hyperlink.NavigateUri = new Uri(href, UriKind.Absolute);
                            hyperlink.Content = word;
                            hyperlink.Template = (ControlTemplate)XamlReader.Load(
                                "<ControlTemplate TargetType='HyperlinkButton' xmlns='http://schemas.microsoft.com/client/2007' >" +
                                "<TextBlock Text='{TemplateBinding Content}' Padding='0' Margin='0' RenderTransformOrigin='0.5,0.5'>" +
                                "<TextBlock.RenderTransform>" +
                                "<CompositeTransform TranslateY='5' />" +
                                "</TextBlock.RenderTransform>" +
                                "</TextBlock>" +
                                "</ControlTemplate>");
                            hyperlink.FontFamily = new FontFamily("Segoe UI Light");
                            hyperlink.FontWeight = FontWeights.Normal;
                            hyperlink.Margin = new Thickness(0);
                            if (word.EndsWith(" "))
                                hyperlink.Margin = new Thickness(0, 0, 4, 0);
                            hyperlink.Padding = new Thickness(0);
                            var inline_ui_container = new InlineUIContainer();
                            inline_ui_container.Child = hyperlink;

                            inlines.Add(inline_ui_container);
                        }
                    }
                    else
                        inlines.Add(run);

                    linebreak_count = 0;
                }
            }
            return inlines;
        }