Ejemplo n.º 1
0
            protected override void Write(Markdig.Renderers.WpfRenderer renderer,
                                          Markdig.Syntax.Inlines.LinkInline link)
            {
                if (link?.IsImage ?? throw new ArgumentNullException(nameof(link)))
                {
                    if (!new Uri(link.Url, UriKind.RelativeOrAbsolute).IsAbsoluteUri)
                    {
                        Uri u = new Uri(_linkpath, link.Url);
                        link.Url = u.AbsoluteUri;
                    }
                }

                base.Write(renderer, link);
            }
Ejemplo n.º 2
0
        protected override void Write([NotNull] Markdig.Renderers.WpfRenderer renderer, [NotNull] TaskList taskList)
        {
            var checkBox = new CheckBox
            {
                IsChecked = taskList.Checked,
                Tag       = _checkCount,
                Command   = TaskListItemChanged
            };

            checkBox.CommandParameter = checkBox;

            _checkCount++;

            checkBox.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.TaskListStyleKey);
            renderer.WriteInline(new InlineUIContainer(checkBox));
        }
        /// <summary>
        /// Renders the document.
        /// </summary>
        /// only those parts that were changed in the source text are rendered anew.
        /// Note that setting this parameter to <c>true</c> does not force a new rendering of the images; for that, call <see cref="IWpfImageProvider.ClearCache"/> of the <see cref="ImageProvider"/> member before rendering.</param>
        private FlowDocument RenderDocument(string sourceText, System.Globalization.CultureInfo documentCulture)
        {
            var pipeline = Pipeline ?? DefaultPipeline;

            var markdownDocument = Markdig.Markdown.Parse(sourceText, pipeline);

            // We override the renderer with our own writer
            var flowDocument = new FlowDocument
            {
                IsHyphenationEnabled = true,
                Language             = System.Windows.Markup.XmlLanguage.GetLanguage(documentCulture.IetfLanguageTag)
            };

            var renderer = new Markdig.Renderers.WpfRenderer(flowDocument, DynamicStyles.Instance)
            {
                // ImageProvider = ImageProvider
            };

            pipeline.Setup(renderer);
            renderer.Render(markdownDocument);
            return(flowDocument);
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        protected override void Write([NotNull] Markdig.Renderers.WpfRenderer renderer, [NotNull] LinkInline link)
        {
            var url = link.GetDynamicUrl != null?link.GetDynamicUrl() ?? link.Url : link.Url;

            if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
            {
                url = "#";
            }

            if (link.IsImage)
            {
                var image = new Image
                {
                    Source = new BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute))
                };

                image.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.ImageStyleKey);

                renderer.WriteInline(new InlineUIContainer(image));
            }
            else
            {
                var hyperlink = new Hyperlink
                {
                    Command          = Markdig.Wpf.Commands.Hyperlink,
                    CommandParameter = url,
                    NavigateUri      = new Uri(url, UriKind.RelativeOrAbsolute),
                    ToolTip          = link.Title != string.Empty ? link.Title : null,
                };

                hyperlink.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.HyperlinkStyleKey);

                renderer.Push(hyperlink);
                renderer.WriteChildren(link);
                renderer.Pop();
            }
        }