Merge pull request #77151 from connor4312/feat/markdown-render-command

feat(markdown): add render command (fixes #75612)
This commit is contained in:
Matt Bierner
2019-08-20 11:23:47 -07:00
committed by GitHub
6 changed files with 81 additions and 9 deletions

View File

@@ -10,3 +10,4 @@ export { RefreshPreviewCommand } from './refreshPreview';
export { ShowPreviewSecuritySelectorCommand } from './showPreviewSecuritySelector';
export { MoveCursorToPositionCommand } from './moveCursorToPosition';
export { ToggleLockCommand } from './toggleLock';
export { RenderDocument } from './renderDocument';

View File

@@ -0,0 +1,30 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { Command } from '../commandManager';
import { MarkdownEngine } from '../markdownEngine';
import { SkinnyTextDocument } from '../tableOfContentsProvider';
export class RenderDocument implements Command {
public readonly id = 'markdown.render';
public constructor(
private readonly engine: MarkdownEngine
) { }
public async execute(document?: SkinnyTextDocument | string): Promise<string | undefined> {
if (!document) {
if (!vscode.window.activeTextEditor) {
return;
}
document = vscode.window.activeTextEditor.document;
}
return this.engine.render(document);
}
}