Skip to content

Commit fd3cebb

Browse files
committed
More ways to render markdown cells - when cell/notebook is executed, and new action to force it
1 parent 42ec247 commit fd3cebb

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const NOTEBOOK_UNDO = 'notebook.undo';
3333
const NOTEBOOK_CURSOR_UP = 'notebook.cursorUp';
3434
const NOTEBOOK_CURSOR_DOWN = 'notebook.cursorDown';
3535
const CLEAR_ALL_CELLS_OUTPUTS_COMMAND_ID = 'notebook.clearAllCellsOutputs';
36+
const RENDER_ALL_MARKDOWN_CELLS = 'notebook.renderAllMarkdownCells';
3637

3738
// Cell Commands
3839
const INSERT_CODE_CELL_ABOVE_COMMAND_ID = 'notebook.cell.insertCodeCellAbove';
@@ -261,6 +262,22 @@ registerAction2(class extends NotebookAction {
261262
}
262263
});
263264

265+
registerAction2(class extends NotebookAction {
266+
constructor() {
267+
super({
268+
id: RENDER_ALL_MARKDOWN_CELLS,
269+
title: localize('notebookActions.renderMarkdown', "Render All Markdown Cells"),
270+
category: NOTEBOOK_ACTIONS_CATEGORY,
271+
precondition: NOTEBOOK_IS_ACTIVE_EDITOR,
272+
f1: true
273+
});
274+
}
275+
276+
async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise<void> {
277+
renderAllMarkdownCells(context);
278+
}
279+
});
280+
264281
registerAction2(class extends NotebookAction {
265282
constructor() {
266283
super({
@@ -273,10 +290,19 @@ registerAction2(class extends NotebookAction {
273290
}
274291

275292
async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise<void> {
293+
renderAllMarkdownCells(context);
276294
return context.notebookEditor.executeNotebook();
277295
}
278296
});
279297

298+
function renderAllMarkdownCells(context: INotebookCellActionContext): void {
299+
context.notebookEditor.viewModel!.viewCells.forEach(cell => {
300+
if (cell.cellKind === CellKind.Markdown) {
301+
cell.editState = CellEditState.Preview;
302+
}
303+
});
304+
}
305+
280306
registerAction2(class extends NotebookAction {
281307
constructor() {
282308
super({

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,11 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
11301130
}
11311131

11321132
async executeNotebookCell(cell: ICellViewModel): Promise<void> {
1133+
if (cell.cellKind === CellKind.Markdown) {
1134+
cell.editState = CellEditState.Preview;
1135+
return;
1136+
}
1137+
11331138
if (!cell.getEvaluatedMetadata(this.notebookViewModel!.metadata).runnable) {
11341139
return;
11351140
}

0 commit comments

Comments
 (0)