feat(markdown): add render command (fixes #75612)#77151
feat(markdown): add render command (fixes #75612)#77151mjbvz merged 2 commits intomicrosoft:masterfrom
Conversation
This adds a command which renders the provided document, or the active
editor if one is provided. Following the pattern of some of the preview
commands, it returned `undefined` if there's no document provided and
no active text editor. Otherwise, seems to work...
```ts
const html = await vscode.commands.executeCommand<string>('markdown.render');
```
A way to render arbitrary strings in addition to documents may be useful at
some point in the future. However, I didn't implement that here as that'd
require some refactoring of the markdown engine. If we're interested though
I could certainly give that a shot.
|
Yes I'd prefer that this api take a This will make the change a bit more involved so let me know if you have any question about this |
|
Cool, no problem. I'll give it a shot. I think taking a document as an option ( |
|
Considering it more, I'm wondering whether the configuration object is something we'd want to expose. I think the main value add of this functionality is to render a document (or string) with the workspace settings such that it matches the preview, requested in the initial issue. Exposing the options turns this into more of a generic markdown renderer, which imo is not necessarily functionality we want the core editor to provide. It also couples the command API to MarkdownIt; if we wanted to ever change markdown rendering systems, the options might not match up. |
|
Thanks! Will be making some minor changes to api but I'll note these on the original issue |
While I agree philosophically, changing the markdown renderer would break every single extension that extends markdown because they all work by chaining a markdown-it extension. You're already wedded to markdown-it. |
This adds a command which renders the provided document, or the active
editor if one is available. Following the pattern of some of the preview
commands, it returned
undefinedif there's no document provided andno active text editor. Otherwise, seems to work...
A way to render arbitrary strings in addition to documents may be useful at
some point in the future. However, I didn't implement that here as that'd
require some refactoring of the markdown engine. If we're interested though
I could certainly give that a shot.
Fixes #75612