Skip to content

Commit

Permalink
Merge pull request #613 from jcoc611-microsoft/user/juosori/Markdown_…
Browse files Browse the repository at this point in the history
…Readonly_Document

MarkdownTextBlock: Expose MarkdownDocument as a readonly property
  • Loading branch information
Arlodotexe authored Nov 29, 2024
2 parents 501882d + b5baf69 commit b71dbf1
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 b71dbf1

Please sign in to comment.