winston-de / MarkdownFilePreviewExtension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MarkdownFilePreviewExtension

This is an example of an app that extends Files to provide markdown file previews in the preview pane.

Support for previews is provided by the service "com.markdownpreview.controlservice". Files locates the name of this service by reading the service property registered in the app manifest, here. Files also looks at the FileExtensions.json file to get a list of file extensions that the preview service is registered for. If the selected file has an extension listed within this file, then Files will call the extension's service.

How the service works

The service takes the file buffer as a parameter. It then parses that data as a string, and adds it to a string that contains valid xaml. For example, if the input text was "Hello, world!", the xaml would be

<controls:MarkdownTextBlock xml:space="preserve" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">
  <controls:MarkdownTextBlock.Text>
    Hello, world!
  </controls:MarkdownTextBlock.Text>
</controls:MarkdownTextBlock>

The xaml string is them sent back to Files, and loaded using the XamlReader.

About


Languages

Language:C# 100.0%