|
1 | 1 | --- |
2 | | -title: Display markdown content |
3 | | -description: Learn how to display markdown in your Command Palette extension. |
4 | | -ms.date: 3/23/2025 |
| 2 | +title: Display markdown content in Command Palette extensions |
| 3 | +description: Learn how to display markdown content in your Command Palette extension. Create rich documentation, file previews, and interactive tutorials with formatted text and embedded commands. |
| 4 | +ms.date: 09/30/2025 |
5 | 5 | ms.topic: how-to |
6 | 6 | no-loc: [PowerToys, Windows, Insider] |
7 | | -# Customer intent: As a Windows developer, I want to learn how to develop an extension for the Command Palette. |
| 7 | +# Customer intent: As a Windows developer, I want to learn how to develop an extension for the Command Palette that displays markdown content, so that I can provide rich documentation or previews within the Command Palette. |
8 | 8 | --- |
9 | 9 |
|
10 | 10 | # Display markdown content |
11 | 11 |
|
12 | 12 | **Previous**: [Command Results](command-results.md) |
13 | 13 |
|
| 14 | +The Command Palette supports rich content display beyond simple command lists. You can create extensions that show formatted text, documentation, and interactive content using markdown. This capability is particularly useful for: |
| 15 | + |
| 16 | +- Displaying help documentation or user guides |
| 17 | +- Showing file previews or summaries |
| 18 | +- Providing formatted instructions or tutorials |
| 19 | +- Creating interactive content with embedded commands |
| 20 | + |
| 21 | +This article shows you how to create pages that display markdown content in your Command Palette extension. |
| 22 | + |
14 | 23 | So far, we've only shown how to display a list of commands in a **ListPage**. However, you can also display rich content in your extension, such as markdown. This can be useful for showing documentation, or a preview of a document. |
15 | 24 |
|
16 | 25 | ## Working with markdown content |
@@ -63,7 +72,7 @@ public <ExtensionName>CommandsProvider() |
63 | 72 |
|
64 | 73 | In this example, a new `ContentPage` that displays a simple markdown string is created. The 'MarkdownContent' class takes a string of markdown content and renders it in the Command Palette. |
65 | 74 |
|
66 | | - |
| 75 | +:::image type="content" source="../../images/command-palette/markdown.png" alt-text="Screenshot of Command Palette extension displaying markdown content with formatted text and document icon."::: |
67 | 76 |
|
68 | 77 | You can also add multiple blocks of content to a page. For example, you can add two blocks of markdown content. |
69 | 78 |
|
@@ -122,9 +131,39 @@ public class <ExtensionName>Page : ContentPage |
122 | 131 | 1. Select \<ExtensionName\> |
123 | 132 | 1. Press `Enter` key, the docs should open |
124 | 133 |
|
125 | | - |
| 134 | +:::image type="content" source="../../images/command-palette/command-context-item.png" alt-text="Screenshot of Command Palette extension showing CommandContextItem with Open in File Explorer option."::: |
| 135 | + |
| 136 | +## Add images to markdown content |
| 137 | + |
| 138 | +With Command Palette in PowerToys 0.95 and later, you can add images to your markdown content from additional sources using one of the following schemes: |
| 139 | + |
| 140 | +- File scheme: Enables loading images using the `file:` scheme. |
| 141 | + - This scheme intentionally restricts file URIs to absolute paths to ensure correct resolution when passed through the Command Palette extension/host boundary. In most cases, 3rd-party extensions provide the paths. However, the Command Palette host performs the actual loading and would otherwise resolve paths relative to itself. |
| 142 | +- Data scheme: Enables loading images from URIs with the `data:` scheme (both Base64 and URL-encoded forms). |
| 143 | + - **Note**: Before the changes introduced in PowerToys 0.95 and later, the markdown control could hang or become unresponsive when processing very large input, such as images larger than 5 MB or with dimensions exceeding 4000×4000 pixels, or markdown files exceeding 1 MB in size. Even with the changes, it is recommended to keep image file sizes below 5 MB and resize images to reasonable dimensions before embedding. For best results, compress images and split very large markdown content into smaller sections where possible. |
| 144 | +- `ms-appx` scheme: This scheme is now supported for loading images. |
| 145 | + - **Note**: Since the Command Palette host performs the loading, `ms-appx:` resolution applies to the host and not the extensions, which limits its usefulness. |
| 146 | +- `ms-appdata` scheme: This scheme is now supported for loading images. |
| 147 | + - Similar to `ms-appx:`, `ms-appdata:` resolution applies to the host, not the extensions. This limits its usefulness for 3rd-party extensions. |
| 148 | + |
| 149 | +Additionally, Command Palette in PowerToys 0.95 and later introduces the concept of image source hints, implemented as query string parameters piggy-backed on the original URI. |
| 150 | + |
| 151 | +These hints allow extension developers to influence the behavior of images within the markdown content. |
| 152 | + |
| 153 | +- `--x-cmdpal-fit` |
| 154 | + - `none`: No automatic scaling, provides image as is (default) |
| 155 | + - `fit`: Scale to fit the available space |
| 156 | +- `--x-cmdpal-upscale` |
| 157 | + - `true`: Allow upscaling |
| 158 | + - `false`: Downscale only (default) |
| 159 | +- `--x-cmdpal-width`: Desired width in pixels |
| 160 | +- `--x-cmdpal-height`: Desired height in pixels |
| 161 | +- `--x-cmdpal-maxwidth`: Max width in pixels |
| 162 | +- `--x-cmdpal-maxheight`: Max height in pixels |
| 163 | + |
| 164 | +See the [SampleMarkdownImages](https://github.com/microsoft/PowerToys/blob/main/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleMarkdownImagesPage.cs) page in the [SamplePagesExtension](https://github.com/microsoft/PowerToys/tree/main/src/modules/cmdpal/ext/SamplePagesExtension) generic sample project in the PowerToys GitHub repository for examples of using images in your extension's markdown content. |
126 | 165 |
|
127 | | -### Next up: [Get user input with forms](using-form-pages.md) |
| 166 | +## Next up: [Get user input with forms](using-form-pages.md) |
128 | 167 |
|
129 | 168 | ## Related content |
130 | 169 |
|
|
0 commit comments