mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add markdown cell to Notebook (#3014)
* add markdown cell * add markdown preview for Notebook * formatting * address comment
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user