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] Support Extensions #609

Open
nerocui opened this issue Nov 25, 2024 · 1 comment
Open

[MarkdownTextBlock] Support Extensions #609

nerocui opened this issue Nov 25, 2024 · 1 comment

Comments

@nerocui
Copy link
Collaborator

nerocui commented Nov 25, 2024

Proposal: Extensions

The underlying parser Markdig supports extensions. Some of these come bundled with that package, such as Pipe Tables and Diagrams. Others can be added with extra code.

Simple properties for built-in extensions

<md:MarkdownTextBlock UseEmphasisExtras="True" UseAutoLinks="True" Text="..." />

We can ship with a few UseFoo properties that allow to configure the built-in extensions that end up both in the MarkdownPipeline and the Renderer. This makes it super easy to control which Markdown extensions get enabled without having to mess around with a MarkdownPipeline or any C# code.

Custom extensions

Declaration in XAML:

<md:MarkdownTextBlock Text="...">
  <md:MarkdownTextBlock.CustomElements>
    <foo:CustomElement />
  </md:MarkdownTextBlock.CustomElements>
</md:MarkdownTextBlock>

And C#, implementing a new interface we ship IElement:

class CustomElement : IElement<CustomObject>
{
  // Parsing
  public void AddToPipeline(MarkdownPipelineBuilder pipelineBuilder)
  {
    pipelineBuilder.Extensions.Add(...);
  }

  // Rendering
  public UWPObjectRenderer<CustomObject> GetObjectRenderer() => new CustomRenderer();
}

With this approach, we can allow users to add arbitrary extensions on top of the control in a very simple and declarative manner. A quick glance at the XAML tells you all the built-in and custom extensions currently being used.

Originally posted by @jcoc611-microsoft in #536 (comment)

@nerocui
Copy link
Collaborator Author

nerocui commented Nov 25, 2024

We should also try to hide away the implementation of the rendering logic. Right now it's all based on programmatically adding elements to a RichTextBlock, but some day we might change the rendering target to something else or change the rendering code. If we were to expose the ability to directly control the rendering, we should define a set of public APIs that can stay consistent going forward.

@Arlodotexe Arlodotexe moved this to 🆕 New in Toolkit 8.x Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant