Skip to content

Commit

Permalink
MarkdownTextBlock: Expose MarkdownDocument as a readonly property
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Osorio committed Nov 26, 2024
1 parent 6dafb91 commit 5909a80
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.Renderers;
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements;
using Markdig;
using Markdig.Syntax;

namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock;

Expand All @@ -30,6 +31,12 @@ public partial class MarkdownTextBlock : Control
typeof(MarkdownTextBlock),
new PropertyMetadata(null, OnTextChanged));

private static readonly DependencyProperty MarkdownDocumentProperty = DependencyProperty.Register(
nameof(MarkdownDocument),
typeof(MarkdownDocument),
typeof(MarkdownTextBlock),
new PropertyMetadata(null));

public MarkdownConfig Config
{
get => (MarkdownConfig)GetValue(ConfigProperty);
Expand All @@ -42,6 +49,12 @@ public string Text
set => SetValue(TextProperty, value);
}

public MarkdownDocument? MarkdownDocument
{
get => (MarkdownDocument)GetValue(MarkdownDocumentProperty);
private set => SetValue(MarkdownDocumentProperty, value);
}

public event EventHandler<LinkClickedEventArgs>? OnLinkClicked;

internal void RaiseLinkClickedEvent(Uri uri) => OnLinkClicked?.Invoke(this, new LinkClickedEventArgs(uri));
Expand Down Expand Up @@ -102,8 +115,8 @@ private void ApplyText(bool rerender)

if (!string.IsNullOrEmpty(Text))
{
var markdown = Markdown.Parse(Text, _pipeline);
_renderer.Render(markdown);
this.MarkdownDocument = Markdown.Parse(Text, _pipeline);
_renderer.Render(this.MarkdownDocument);
}
}
}
Expand Down

0 comments on commit 5909a80

Please sign in to comment.