menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Theia

Eclipse Theia - Cloud & Desktop IDE

Channels
Team

Open a Markdown file in Markdown preview

January 14, 2020 at 6:56am

Open a Markdown file in Markdown preview

January 14, 2020 at 6:56am
Is there a way to programmatically open markdown file automatically in markdown preview

January 14, 2020 at 7:56am
open(openerService, markdownFileUri, { preview: true }) - try like that
like-fill
1

February 6, 2020 at 9:46am
This opens the Markdown file but not in preview mode
Sample Code:
@injectable()
export class MarkDownPrevOpener implements CommandContribution {
constructor(
@inject(WorkspaceService) private readonly workspaceService: WorkspaceService,
@inject(OpenerService) private readonly openerService: OpenerService
) { }
registerCommands(registry: CommandRegistry): void {
registry.registerCommand(PrevCommand, {
execute: async () => {
const uriStr = this.workspaceService.workspace?.uri;
const uri = new URI(uriStr + "/README.md");
open(this.openerService, uri, { preview: true });
}
});
}
}
Edited

February 7, 2020 at 3:37pm
Works perfectly 👍