Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MarkdownTextBlock: Adds OnMarkdownParsed event #616

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jcoc611-microsoft
Copy link

Adds an event MarkdownTextBlock.OnMarkdownParsed, which is useful because consumers cannot otherwise know when the MarkdownDocument has finished being generated from the markdown text input. It also technically allows consumers to mutate the markdown parsed tree before the render step takes place.

@@ -116,6 +114,7 @@ private void ApplyText(bool rerender)
if (!string.IsNullOrEmpty(Text))
{
this.MarkdownDocument = Markdown.Parse(Text, _pipeline);
OnMarkdownParsed?.Invoke(this, new MarkdownParsedEventArgs(this.MarkdownDocument));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is a 1-1 relationship between MarkdownTextBlock and its MarkdownDocument, so I would remove the Document property from the MarkdownParsedEventArgs, as you can get that from the sender.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time you change the Text property of MarkdownTextBlock, technically you would get a brand new MarkdownDocument tree. If we also move the parsing to another thread, technically there would be no guarantees that the MarkdownDocument currently set on the control is the one corresponding to the given event, especially in streaming contexts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants