Skip to content

How to add a plugin

whistyun edited this page Oct 2, 2022 · 2 revisions

A MdXaml plugin add syntaxes and additional supported image formats. For now, there are two official plugins; MdXaml.Html to add html tag support and MdXaml.Svg to add SVG support.

Samples

There are two ways to inject plugins into MdXaml. The first is described in App.xaml. This applies to all MarkdownScrollViewers. The second is described in MarkdownScrollViewer or Markdown. This applies to individual components.

Add nupkg

MdXaml.Plugins is required for custormising plugin. And...

  • If you want html support, please add MdXaml.Html.
  • If you want svg support, please add MdXaml.Svg.

Setup in App.xaml

Add MdXamlPlugins to Application.Resources. Any value can be set for the resource key. MarkdownScrollViewer looks for plugins at Application.Resources and loads them.

App.xaml:

<Application x:Class="***"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mdplug="clr-namespace:MdXaml.Plugins;assembly=MdXaml.Plugins"
             xmlns:mdhtml="clr-namespace:MdXaml.Html;assembly=MdXaml.Html"
             xmlns:mdsvg="clr-namespace:MdXaml.Svg;assembly=MdXaml.Svg"
             StartupUri="***">
    <Application.Resources>
        <mdplug:MdXamlPlugins x:Key="MdXamlPlugins">
            <mdhtml:HtmlPluginSetup/>
            <mdsvg:SvgPluginSetup/>
        </mdplug:MdXamlPlugins>
    </Application.Resources>
</Application>

Appendix: Individual settings at Markdown or MarkdownScrollViewer

<!-- xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml" -->
<!-- xmlns:mdplug="clr-namespace:MdXaml.Plugins;assembly=MdXaml" -->
<!-- xmlns:mdhtml="clr-namespace:MdXaml.Html;assembly=MdXaml.Html" -->
<!-- xmlns:mdsvg="clr-namespace:MdXaml.Svg;assembly=MdXaml.Svg" -->

<mdxam:MarkdownScrollViewer>
	<mdxam:MarkdownScrollViewer.Plugins>
		<mdplug:MdXamlPlugins>
			<mdhtml:HtmlPluginSetup/>
			<mdsvg:SvgPluginSetup/>
		</mdplug:MdXamlPlugins>
	</mdxam:MarkdownScrollViewer.Plugins>
</mdxam:MarkdownScrollViewer>