New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "Render all markdown cells" command #6029
Changes from 5 commits
11823ea
fe9195c
7fe1921
ad086c6
b1074ec
74c5398
0f66b28
153e630
6a4a91b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,8 @@ export namespace CommandIDs { | |
|
||
export const runAll = 'runmenu:run-all'; | ||
|
||
export const runAllMarkdown = 'runmenu:run-all-markdown'; | ||
|
||
export const restartAndRunAll = 'runmenu:restart-and-run-all'; | ||
|
||
export const runAbove = 'runmenu:run-above'; | ||
|
@@ -675,6 +677,13 @@ export function createRunMenu(app: JupyterFrontEnd, menu: RunMenu): void { | |
execute: Private.delegateExecute(app, menu.codeRunners, 'runAll') | ||
}); | ||
|
||
commands.addCommand(CommandIDs.runAllMarkdown, { | ||
label: () => { | ||
return `Render All Markdown Cells`; | ||
}, | ||
isEnabled: Private.delegateEnabled(app, menu.codeRunners, 'runAllMarkdown'), | ||
execute: Private.delegateExecute(app, menu.codeRunners, 'runAllMarkdown') | ||
}); | ||
commands.addCommand(CommandIDs.restartAndRunAll, { | ||
label: () => { | ||
const noun = Private.delegateLabel(app, menu.codeRunners, 'noun'); | ||
|
@@ -693,11 +702,13 @@ export function createRunMenu(app: JupyterFrontEnd, menu: RunMenu): void { | |
execute: Private.delegateExecute(app, menu.codeRunners, 'restartAndRunAll') | ||
}); | ||
|
||
const runAllGroup = [CommandIDs.runAll, CommandIDs.restartAndRunAll].map( | ||
command => { | ||
return { command }; | ||
} | ||
); | ||
const runAllGroup = [ | ||
CommandIDs.runAll, | ||
CommandIDs.restartAndRunAll, | ||
CommandIDs.runAllMarkdown | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line can be removed. |
||
].map(command => { | ||
return { command }; | ||
}); | ||
|
||
menu.addGroup([{ command: CommandIDs.run }], 0); | ||
menu.addGroup(runAllGroup, 999); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,8 @@ export namespace IRunMenu { | |
*/ | ||
runAll?: (widget: T) => Promise<void>; | ||
|
||
runAllMarkdown?: (widget: T) => Promise<void>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
/** | ||
* A function to restart and run all the code hosted by the widget, which | ||
* returns a promise of whether the action was performed. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,8 @@ namespace CommandIDs { | |
|
||
export const runAllBelow = 'notebook:run-all-below'; | ||
|
||
export const runAllMarkdown = 'notebook:run-all-markdown'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe better to name it |
||
|
||
export const toCode = 'notebook:change-cell-to-code'; | ||
|
||
export const toMarkdown = 'notebook:change-cell-to-markdown'; | ||
|
@@ -1037,6 +1039,17 @@ function addCommands( | |
); | ||
} | ||
}); | ||
commands.addCommand(CommandIDs.runAllMarkdown, { | ||
label: 'Render All Markdown Cells', | ||
execute: args => { | ||
const current = getCurrent(args); | ||
if (current) { | ||
const { context, content } = current; | ||
return NotebookActions.runAllMarkdown(content, context.session); | ||
} | ||
}, | ||
isEnabled | ||
}); | ||
commands.addCommand(CommandIDs.restart, { | ||
label: 'Restart Kernel…', | ||
execute: args => { | ||
|
@@ -1788,6 +1801,7 @@ function populatePalette( | |
CommandIDs.restartClear, | ||
CommandIDs.restartRunAll, | ||
CommandIDs.runAll, | ||
CommandIDs.runAllMarkdown, | ||
CommandIDs.runAllAbove, | ||
CommandIDs.runAllBelow, | ||
CommandIDs.selectAll, | ||
|
@@ -2062,6 +2076,12 @@ function populateMenus( | |
() => void 0 | ||
); | ||
}, | ||
runAllMarkdown: current => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where you would add a group containing the |
||
const { context, content } = current; | ||
return NotebookActions.runAllMarkdown(content, context.session).then( | ||
() => void 0 | ||
); | ||
}, | ||
restartAndRunAll: current => { | ||
const { context, content } = current; | ||
return context.session.restart().then(restarted => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -526,6 +526,32 @@ export namespace NotebookActions { | |
return promise; | ||
} | ||
|
||
export function runAllMarkdown( | ||
notebook: Notebook, | ||
session?: IClientSession | ||
): Promise<boolean> { | ||
if (!notebook.model || !notebook.activeCell) { | ||
return Promise.resolve(false); | ||
} | ||
const previousIndex = notebook.activeCellIndex; | ||
const state = Private.getState(notebook); | ||
notebook.widgets.forEach((child, index) => { | ||
if (child.model.type === 'markdown') { | ||
notebook.select(child); | ||
// This is to make sure that the activeCell | ||
// does not get executed | ||
notebook.activeCellIndex = index; | ||
} | ||
}); | ||
if (notebook.widgets[notebook.activeCellIndex].model.type !== 'markdown') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can make this a bit simpler by accessing |
||
return Promise.resolve(true); | ||
} | ||
const promise = Private.runSelected(notebook, session); | ||
notebook.activeCellIndex = previousIndex; | ||
Private.handleRunState(notebook, state, true); | ||
return promise; | ||
} | ||
|
||
/** | ||
* Run all of the cells before the currently active cell (exclusive). | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this ID should be here at all -- there is no
'runmenu:run-all-markdown'
command defined as far as I see.