Add markdown cell to Notebook (#3014)

* add markdown cell

* add markdown preview for Notebook

* formatting

* address comment
This commit is contained in:
Abbie Petchtes
2018-10-26 16:20:06 -07:00
committed by GitHub
parent 2859bee4c0
commit 533f2734f1
15 changed files with 162 additions and 19 deletions

View File

@@ -8,7 +8,8 @@ import * as vscode from 'vscode';
export interface Command {
readonly id: string;
execute(...args: any[]): void;
// {{SQL CARBON EDIT}}
execute(...args: any[]): any;
}
export class CommandManager {
@@ -26,7 +27,8 @@ export class CommandManager {
return command;
}
private registerCommand(id: string, impl: (...args: any[]) => void, thisArg?: any) {
// {{SQL CARBON EDIT}}
private registerCommand(id: string, impl: (...args: any[]) => any, thisArg?: any) {
if (this.commands.has(id)) {
return;
}

View File

@@ -11,3 +11,5 @@ export { RefreshPreviewCommand } from './refreshPreview';
export { ShowPreviewSecuritySelectorCommand } from './showPreviewSecuritySelector';
export { MoveCursorToPositionCommand } from './moveCursorToPosition';
export { ToggleLockCommand } from './toggleLock';
// {{SQL CARBON EDIT}}
export { ShowNotebookPreview } from './showNotebookPreview';

View File

@@ -0,0 +1,20 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { Command } from '../commandManager';
import { MarkdownEngine } from '../markdownEngine';
export class ShowNotebookPreview implements Command {
public readonly id = 'notebook.showPreview';
public constructor(
private readonly engine: MarkdownEngine
) { }
public async execute(document: vscode.Uri, textContent: string): Promise<string> {
return this.engine.renderText(document, textContent);
}
}

View File

@@ -59,6 +59,8 @@ export function activate(context: vscode.ExtensionContext) {
commandManager.register(new commands.OnPreviewStyleLoadErrorCommand());
commandManager.register(new commands.OpenDocumentLinkCommand(engine));
commandManager.register(new commands.ToggleLockCommand(previewManager));
// {{SQL CARBON EDIT}}
commandManager.register(new commands.ShowNotebookPreview(engine));
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => {
logger.updateConfiguration();

View File

@@ -86,6 +86,12 @@ export class MarkdownEngine {
return { text, offset };
}
// {{SQL CARBON EDIT}}
public async renderText(document: vscode.Uri, text: string): Promise<string> {
const engine = await this.getEngine(document);
return engine.render(text);
}
public async render(document: vscode.Uri, stripFrontmatter: boolean, text: string): Promise<string> {
let offset = 0;
if (stripFrontmatter) {