diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts index ad61dd49744..0f08af3b984 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts @@ -33,6 +33,7 @@ const NOTEBOOK_UNDO = 'notebook.undo'; const NOTEBOOK_CURSOR_UP = 'notebook.cursorUp'; const NOTEBOOK_CURSOR_DOWN = 'notebook.cursorDown'; const CLEAR_ALL_CELLS_OUTPUTS_COMMAND_ID = 'notebook.clearAllCellsOutputs'; +const RENDER_ALL_MARKDOWN_CELLS = 'notebook.renderAllMarkdownCells'; // Cell Commands const INSERT_CODE_CELL_ABOVE_COMMAND_ID = 'notebook.cell.insertCodeCellAbove'; @@ -261,6 +262,22 @@ registerAction2(class extends NotebookAction { } }); +registerAction2(class extends NotebookAction { + constructor() { + super({ + id: RENDER_ALL_MARKDOWN_CELLS, + title: localize('notebookActions.renderMarkdown', "Render All Markdown Cells"), + category: NOTEBOOK_ACTIONS_CATEGORY, + precondition: NOTEBOOK_IS_ACTIVE_EDITOR, + f1: true + }); + } + + async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise { + renderAllMarkdownCells(context); + } +}); + registerAction2(class extends NotebookAction { constructor() { super({ @@ -273,10 +290,19 @@ registerAction2(class extends NotebookAction { } async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise { + renderAllMarkdownCells(context); return context.notebookEditor.executeNotebook(); } }); +function renderAllMarkdownCells(context: INotebookCellActionContext): void { + context.notebookEditor.viewModel!.viewCells.forEach(cell => { + if (cell.cellKind === CellKind.Markdown) { + cell.editState = CellEditState.Preview; + } + }); +} + registerAction2(class extends NotebookAction { constructor() { super({ diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index cfee10b8f04..bf3aaf47ab0 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -1130,6 +1130,11 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor } async executeNotebookCell(cell: ICellViewModel): Promise { + if (cell.cellKind === CellKind.Markdown) { + cell.editState = CellEditState.Preview; + return; + } + if (!cell.getEvaluatedMetadata(this.notebookViewModel!.metadata).runnable) { return; }