/// <summary> /// Called to preform a render of the current Markdown. /// </summary> private void RenderMarkdown() { // Make sure we have something to parse. if (string.IsNullOrWhiteSpace(Text)) { return; } // Leave if we don't have our root yet. if (_rootElement == null) { return; } // Disconnect from OnClick handlers. UnhookListeners(); MarkdownRenderedEventArgs markdownRenderedArgs = new MarkdownRenderedEventArgs(null); try { // Try to parse the markdown. MarkdownDocument markdown = new MarkdownDocument(); markdown.Parse(Text); // Now try to display it var renderer = new XamlRenderer(markdown, this, this) { Background = Background, BorderBrush = BorderBrush, BorderThickness = BorderThickness, CharacterSpacing = CharacterSpacing, FontFamily = FontFamily, FontSize = FontSize, FontStretch = FontStretch, FontStyle = FontStyle, FontWeight = FontWeight, Foreground = Foreground, IsTextSelectionEnabled = IsTextSelectionEnabled, Padding = Padding, CodeBackground = CodeBackground, CodeBorderBrush = CodeBorderBrush, CodeBorderThickness = CodeBorderThickness, CodeForeground = CodeForeground, CodeFontFamily = CodeFontFamily, CodePadding = CodePadding, CodeMargin = CodeMargin, Header1FontSize = Header1FontSize, Header1FontWeight = Header1FontWeight, Header1Margin = Header1Margin, Header1Foreground = Header1Foreground, Header2FontSize = Header2FontSize, Header2FontWeight = Header2FontWeight, Header2Margin = Header2Margin, Header2Foreground = Header2Foreground, Header3FontSize = Header3FontSize, Header3FontWeight = Header3FontWeight, Header3Margin = Header3Margin, Header3Foreground = Header3Foreground, Header4FontSize = Header4FontSize, Header4FontWeight = Header4FontWeight, Header4Margin = Header4Margin, Header4Foreground = Header4Foreground, Header5FontSize = Header5FontSize, Header5FontWeight = Header5FontWeight, Header5Margin = Header5Margin, Header5Foreground = Header5Foreground, Header6FontSize = Header6FontSize, Header6FontWeight = Header6FontWeight, Header6Margin = Header6Margin, Header6Foreground = Header6Foreground, HorizontalRuleBrush = HorizontalRuleBrush, HorizontalRuleMargin = HorizontalRuleMargin, HorizontalRuleThickness = HorizontalRuleThickness, ListMargin = ListMargin, ListGutterWidth = ListGutterWidth, ListBulletSpacing = ListBulletSpacing, ParagraphMargin = ParagraphMargin, QuoteBackground = QuoteBackground, QuoteBorderBrush = QuoteBorderBrush, QuoteBorderThickness = QuoteBorderThickness, QuoteForeground = QuoteForeground, QuoteMargin = QuoteMargin, QuotePadding = QuotePadding, TableBorderBrush = TableBorderBrush, TableBorderThickness = TableBorderThickness, TableCellPadding = TableCellPadding, TableMargin = TableMargin, TextWrapping = TextWrapping, LinkForeground = LinkForeground, ImageStretch = ImageStretch }; _rootElement.Child = renderer.Render(); } catch (Exception ex) { DebuggingReporter.ReportCriticalError("Error while parsing and rendering: " + ex.Message); markdownRenderedArgs = new MarkdownRenderedEventArgs(ex); } // Indicate that the parse is done. MarkdownRendered?.Invoke(this, markdownRenderedArgs); }
/// <summary> /// Called to preform a render of the current Markdown. /// </summary> private void RenderMarkdown() { // Leave if we don't have our root yet. if (_rootElement == null) { return; } // Disconnect from OnClick handlers. UnhookListeners(); var markdownRenderedArgs = new MarkdownRenderedEventArgs(null); // Make sure we have something to parse. if (string.IsNullOrWhiteSpace(Text)) { _rootElement.Child = null; } else { try { // Try to parse the markdown. MarkdownDocument markdown = new MarkdownDocument(); foreach (string str in SchemeList.Split(',').ToList()) { if (!string.IsNullOrEmpty(str)) { MarkdownDocument.KnownSchemes.Add(str); } } markdown.Parse(Text); // Now try to display it var renderer = Activator.CreateInstance(renderertype, markdown, this, this, this) as MarkdownRenderer; if (renderer == null) { throw new Exception("Markdown Renderer was not of the correct type."); } renderer.Background = Background; renderer.BorderBrush = BorderBrush; renderer.BorderThickness = BorderThickness; renderer.CharacterSpacing = CharacterSpacing; renderer.FontFamily = FontFamily; renderer.FontSize = FontSize; renderer.FontStretch = FontStretch; renderer.FontStyle = FontStyle; renderer.FontWeight = FontWeight; renderer.Foreground = Foreground; renderer.IsTextSelectionEnabled = IsTextSelectionEnabled; renderer.Padding = Padding; renderer.CodeBackground = CodeBackground; renderer.CodeBorderBrush = CodeBorderBrush; renderer.CodeBorderThickness = CodeBorderThickness; renderer.InlineCodeBorderThickness = InlineCodeBorderThickness; renderer.InlineCodeBackground = InlineCodeBackground; renderer.InlineCodeBorderBrush = InlineCodeBorderBrush; renderer.InlineCodePadding = InlineCodePadding; renderer.InlineCodeFontFamily = InlineCodeFontFamily; renderer.InlineCodeForeground = InlineCodeForeground; renderer.CodeForeground = CodeForeground; renderer.CodeFontFamily = CodeFontFamily; renderer.CodePadding = CodePadding; renderer.CodeMargin = CodeMargin; renderer.EmojiFontFamily = EmojiFontFamily; renderer.Header1FontSize = Header1FontSize; renderer.Header1FontWeight = Header1FontWeight; renderer.Header1Margin = Header1Margin; renderer.Header1Foreground = Header1Foreground; renderer.Header2FontSize = Header2FontSize; renderer.Header2FontWeight = Header2FontWeight; renderer.Header2Margin = Header2Margin; renderer.Header2Foreground = Header2Foreground; renderer.Header3FontSize = Header3FontSize; renderer.Header3FontWeight = Header3FontWeight; renderer.Header3Margin = Header3Margin; renderer.Header3Foreground = Header3Foreground; renderer.Header4FontSize = Header4FontSize; renderer.Header4FontWeight = Header4FontWeight; renderer.Header4Margin = Header4Margin; renderer.Header4Foreground = Header4Foreground; renderer.Header5FontSize = Header5FontSize; renderer.Header5FontWeight = Header5FontWeight; renderer.Header5Margin = Header5Margin; renderer.Header5Foreground = Header5Foreground; renderer.Header6FontSize = Header6FontSize; renderer.Header6FontWeight = Header6FontWeight; renderer.Header6Margin = Header6Margin; renderer.Header6Foreground = Header6Foreground; renderer.HorizontalRuleBrush = HorizontalRuleBrush; renderer.HorizontalRuleMargin = HorizontalRuleMargin; renderer.HorizontalRuleThickness = HorizontalRuleThickness; renderer.ListMargin = ListMargin; renderer.ListGutterWidth = ListGutterWidth; renderer.ListBulletSpacing = ListBulletSpacing; renderer.ParagraphMargin = ParagraphMargin; renderer.ParagraphLineHeight = ParagraphLineHeight; renderer.QuoteBackground = QuoteBackground; renderer.QuoteBorderBrush = QuoteBorderBrush; renderer.QuoteBorderThickness = QuoteBorderThickness; renderer.QuoteForeground = QuoteForeground; renderer.QuoteMargin = QuoteMargin; renderer.QuotePadding = QuotePadding; renderer.TableBorderBrush = TableBorderBrush; renderer.TableBorderThickness = TableBorderThickness; renderer.YamlBorderBrush = YamlBorderBrush; renderer.YamlBorderThickness = YamlBorderThickness; renderer.TableCellPadding = TableCellPadding; renderer.TableMargin = TableMargin; renderer.TextWrapping = TextWrapping; renderer.LinkForeground = LinkForeground; renderer.ImageStretch = ImageStretch; renderer.ImageMaxHeight = ImageMaxHeight; renderer.ImageMaxWidth = ImageMaxWidth; renderer.WrapCodeBlock = WrapCodeBlock; renderer.FlowDirection = FlowDirection; _rootElement.Child = renderer.Render(); } catch (Exception ex) { Debug.WriteLine("Error while parsing and rendering: " + ex.Message); if (Debugger.IsAttached) { Debugger.Break(); } markdownRenderedArgs = new MarkdownRenderedEventArgs(ex); } } // Indicate that the parse is done. MarkdownRendered?.Invoke(this, markdownRenderedArgs); }
/// <summary> /// Called to preform a render of the current Markdown. /// </summary> private void RenderMarkdown() { if (_rootElement == null) { return; } if (_flowDocumentScrollViewer == null) { _flowDocumentScrollViewer = new FlowDocumentScrollViewer() { VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; DataObject.AddCopyingHandler(_flowDocumentScrollViewer, OnCopy); _rootElement.Child = _flowDocumentScrollViewer; } UnhookListeners(); _listeningHyperlinks.Clear(); var markdownRenderedArgs = new MarkdownRenderedEventArgs(null); if (string.IsNullOrWhiteSpace(Text)) { _flowDocumentScrollViewer.Document = null; } else { try { MarkdownDocument markdown = new MarkdownDocument(); foreach (string str in SchemeList.Split(',').ToList()) { if (!string.IsNullOrEmpty(str)) { MarkdownDocument.KnownSchemes.Add(str); } } markdown.Parse(Text); if (!(Activator.CreateInstance(renderertype, markdown, this, this, this, this) is MarkdownRenderer renderer)) { throw new Exception("Markdown Renderer was not of the correct type."); } renderer.FontFamily = FontFamily; renderer.FontSize = FontSize; renderer.FontStretch = FontStretch; renderer.FontStyle = FontStyle; renderer.FontWeight = FontWeight; renderer.Foreground = Foreground; renderer.Padding = Padding; renderer.CodeBackground = CodeBackground; renderer.CodeBorderBrush = CodeBorderBrush; renderer.CodeBorderThickness = CodeBorderThickness; renderer.InlineCodeBorderThickness = InlineCodeBorderThickness; renderer.InlineCodeBackground = InlineCodeBackground; renderer.InlineCodeBorderBrush = InlineCodeBorderBrush; renderer.InlineCodePadding = InlineCodePadding; renderer.InlineCodeFontFamily = InlineCodeFontFamily; renderer.InlineCodeForeground = InlineCodeForeground; renderer.CodeForeground = CodeForeground; renderer.CodeFontFamily = CodeFontFamily; renderer.CodePadding = CodePadding; renderer.CodeMargin = CodeMargin; renderer.EmojiFontFamily = EmojiFontFamily; renderer.Header1FontSize = Header1FontSize; renderer.Header1FontWeight = Header1FontWeight; renderer.Header1Margin = Header1Margin; renderer.Header1Foreground = Header1Foreground; renderer.Header2FontSize = Header2FontSize; renderer.Header2FontWeight = Header2FontWeight; renderer.Header2Margin = Header2Margin; renderer.Header2Foreground = Header2Foreground; renderer.Header3FontSize = Header3FontSize; renderer.Header3FontWeight = Header3FontWeight; renderer.Header3Margin = Header3Margin; renderer.Header3Foreground = Header3Foreground; renderer.Header4FontSize = Header4FontSize; renderer.Header4FontWeight = Header4FontWeight; renderer.Header4Margin = Header4Margin; renderer.Header4Foreground = Header4Foreground; renderer.Header5FontSize = Header5FontSize; renderer.Header5FontWeight = Header5FontWeight; renderer.Header5Margin = Header5Margin; renderer.Header5Foreground = Header5Foreground; renderer.Header6FontSize = Header6FontSize; renderer.Header6FontWeight = Header6FontWeight; renderer.Header6Margin = Header6Margin; renderer.Header6Foreground = Header6Foreground; renderer.HorizontalRuleBrush = HorizontalRuleBrush; renderer.HorizontalRuleMargin = HorizontalRuleMargin; renderer.HorizontalRuleThickness = HorizontalRuleThickness; renderer.ListMargin = ListMargin; renderer.ListBulletSpacing = ListBulletSpacing; renderer.ParagraphMargin = ParagraphMargin; renderer.ParagraphLineHeight = ParagraphLineHeight; renderer.QuoteBackground = QuoteBackground; renderer.QuoteBorderBrush = QuoteBorderBrush; renderer.QuoteBorderThickness = QuoteBorderThickness; renderer.QuoteForeground = QuoteForeground; renderer.QuoteMargin = QuoteMargin; renderer.QuotePadding = QuotePadding; renderer.TableBorderBrush = TableBorderBrush; renderer.TableBorderThickness = TableBorderThickness; renderer.YamlBorderBrush = YamlBorderBrush; renderer.YamlBorderThickness = YamlBorderThickness; renderer.TableCellPadding = TableCellPadding; renderer.TableMargin = TableMargin; renderer.LinkForeground = LinkForeground; renderer.ImageStretch = ImageStretch; renderer.ImageMaxHeight = ImageMaxHeight; renderer.ImageMaxWidth = ImageMaxWidth; renderer.FlowDirection = FlowDirection; _flowDocumentScrollViewer.IsSelectionEnabled = IsTextSelectionEnabled; _flowDocumentScrollViewer.Document = renderer.Render(); } catch (Exception ex) { Debug.WriteLine("Error while parsing and rendering: " + ex.Message); if (Debugger.IsAttached) { Debugger.Break(); } markdownRenderedArgs = new MarkdownRenderedEventArgs(ex); } } MarkdownRendered?.Invoke(this, markdownRenderedArgs); }