Skip to content
Snippets Groups Projects
Commit 79938d26 authored by sheepmax's avatar sheepmax
Browse files

Add keep output

parent 13328deb
No related branches found
No related tags found
3 merge requests!135Update 2 files,!120New thebe features,!101Thebe new features: tags, aesthetics, default ipywidgets install
Pipeline #207913 passed
%% Cell type:markdown id: tags:
# Benchmarks: cell tags
This page includes benchmarks for the behaviour of different cell tags with Thebe.
%% Cell type:code id: tags:thebe-init,disable-download
%% Cell type:code id: tags:thebe-init,disable-download,auto-execute
``` python
# Thebe init
print("This should show on startup")
```
%% Cell type:code id: tags:hide-input
``` python
# Hide input
print("You shouldn't be able to see this without expanding the dropdown.")
print("But the output should be shown outside of it!")
```
%% Cell type:code id: tags:thebe-remove-input-init
``` python
# Remove input
print("This should be shown despite the lack of input.")
```
%% Cell type:code id: tags:thebe-remove-input-init
``` python
# Remove input should preserve placeholder output
print("This output should still be shown until execution.")
```
%% Output
This output should still be shown until execution.
%% Cell type:code id: tags:
``` python
# Predefined output should be removed upon execution
print("Already ran this locally")
```
%% Output
Already ran this locally
%% Cell type:code id: tags:hide-input
``` python
# Hide input with predefined output should show predefined output until execution
print("I'm free from the dropdown!")
```
%% Output
I'm free from the dropdown!
%% Cell type:code id: tags:
%% Cell type:code id: tags:remove-input,keep-output
``` python
import json
from jupyterquiz import display_quiz
with open("../jupyterquizexample.json", "r") as file:
questions=json.load(file)
display_quiz(questions, border_radius=0)
```
%% Output
......
......@@ -195,10 +195,14 @@ var modifyDOMForThebe = () => {
// We remove all pre-existing cell output because they play poorly with Thebe
// This also means we need special tracking for cells with removed input because no HTML is generated for their input
// Hopefully we can achieve this with minimal changes and a special new tag
const outputDivs = document.querySelectorAll(".cell_output");
outputDivs.forEach((div, _) => div.remove());
// Find all code cells, replace with Thebe interactive code cells
const cellOutputs = document.querySelectorAll(".cell_output");
cellOutputs.forEach((output, index) => {
if (output && !output.classList.contains("keep")) {
output.remove();
}
});
const codeCells = document.querySelectorAll(thebe_selector);
codeCells.forEach((codeCell, index) => {
const codeCellId = (index) => `codecell${index}`;
......@@ -213,12 +217,6 @@ var modifyDOMForThebe = () => {
if (codeCellText) {
codeCellText.setAttribute("data-language", dataLanguage);
codeCellText.setAttribute("data-executable", "true");
// If we had an output, insert it just after the `pre` cell
if (codeCellOutput) {
$(codeCellOutput).attr("data-output", "");
$(codeCellOutput).insertAfter(codeCellText);
}
}
// Remove sphinx-copybutton blocks, which are common in Sphinx
......@@ -506,6 +504,14 @@ function handleDisableDownloadTag(element) {
$(".dropdown-download-buttons").remove();
}
function handleAutoExecuteTag(element) {
$(".dropdown-launch-buttons button").click();
}
function handleKeepOutputTag(element) {
element.querySelector(".cell_output").classList.add("keep");
}
// Deal with custom-defined tags to properly prepare Thebe and DOM
// Current special tags: thebe-remove-input-init
function consumeSpecialTags() {
......@@ -513,6 +519,8 @@ function consumeSpecialTags() {
{ tag: "thebe-remove-input-init", handler: handleThebeRemoveInputTag },
{ tag: "disable-execution", handler: handleDisableExecutionTag },
{ tag: "disable-download", handler: handleDisableDownloadTag },
{ tag: "auto-execute", handler: handleAutoExecuteTag },
{ tag: "keep-output", handler: handleKeepOutputTag },
];
window.specialTaggedElements = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment