public void SetMarkup(MiniMarkupBase markup)
        {
            this.Document.Blocks.Clear();
            var x = Render(markup);

            if (x is Section sect)
            {
                this.Document.Blocks.Add(sect);
            }
        }
        private object Render(MiniMarkupBase markup)
        {
            this.IsDocumentEnabled = true;
            this.IsEnabled         = true;
            this.IsReadOnly        = true;

            if (markup is MiniMarkupLine line)
            {
                var p = new Paragraph();

                p.Margin = new Thickness(0);
                if (line.Children != null)
                {
                    foreach (var ch in line.Children)
                    {
                        var x = Render(ch);
                        if (x is Run r)
                        {
                            p.Inlines.Add(r);
                        }
                        if (x is Hyperlink hl)
                        {
                            p.Inlines.Add(hl);
                        }
                    }
                }
                return(p);
            }
            else
            if (markup is MiniMarkupLink mml)
            {
                var link = new Hyperlink();
                link.IsEnabled = true;

                try
                {
                    link.Inlines.Add("" + mml.Text);
                    link.NavigateUri      = new Uri("" + mml.LinkUri);
                    link.RequestNavigate += (s, a) =>
                    {
                        MiniMarkupLinkClick?.Invoke(markup, mml.LinkUri);
                    };
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                }

                return(link);
            }
            else
            if (markup is MiniMarkupRun run)
            {
                var txt = run.Text;
                if (run.Padsize.HasValue)
                {
                    txt = txt.PadRight(run.Padsize.Value);
                }

                var r = new Run(txt);
                if (run.FontSize.HasValue)
                {
                    r.FontSize = run.FontSize.Value;
                }
                if (run.IsBold)
                {
                    r.FontWeight = FontWeights.Bold;
                }
                if (run.IsMonospaced)
                {
                    r.FontFamily = new FontFamily("Courier New");
                }

                return(r);
            }
            else
            if (markup is MiniMarkupSequence seq)
            {
                var s = new Section();

                if (seq.Children != null)
                {
                    foreach (var ch in seq.Children)
                    {
                        var x = Render(ch);
                        if (x is Block r)
                        {
                            s.Blocks.Add(r);
                        }
                    }
                }
                return(s);
            }

            return(null);
        }
Пример #3
0
        private object Render(MiniMarkupBase markup)
        {
            if (markup is MiniMarkupLine line)
            {
                var p = new Paragraph();
                p.Margin = new Thickness(0);
                if (line.Children != null)
                {
                    foreach (var ch in line.Children)
                    {
                        var x = Render(ch);
                        if (x is Run r)
                        {
                            p.Inlines.Add(r);
                        }
                    }
                }
                return(p);
            }

            if (markup is MiniMarkupRun run)
            {
                var txt = run.Text;
                if (run.Padsize.HasValue)
                {
                    txt = txt.PadRight(run.Padsize.Value);
                }

                var r = new Run(txt);
                if (run.FontSize.HasValue)
                {
                    r.FontSize = run.FontSize.Value;
                }
                if (run.IsBold)
                {
                    r.FontWeight = FontWeights.Bold;
                }
                if (run.IsMonospaced)
                {
                    r.FontFamily = new FontFamily("Courier New");
                }

                return(r);
            }

            if (markup is MiniMarkupSequence seq)
            {
                var s = new Section();
                if (seq.Children != null)
                {
                    foreach (var ch in seq.Children)
                    {
                        var x = Render(ch);
                        if (x is Block r)
                        {
                            s.Blocks.Add(r);
                        }
                    }
                }
                return(s);
            }

            return(null);
        }