MCPcopy Index your code
hub / github.com/RustPython/RustPython / executeNotebook

Function executeNotebook

wasm/notebook/src/index.js:148–256  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

146// 2. get and run content of all tabs (including dynamically added ones)
147// 3. run main tab.
148async function executeNotebook() {
149 // Clean the console and errors
150 notebook.innerHTML = '';
151 error.textContent = '';
152
153 // get the content of the css editor
154 // and add the css to the head
155 // use dataset.status for a flag to know when to update
156 let cssCode = buffers['css'].getValue();
157 let cssStatus = checkCssStatus();
158 switch (cssStatus) {
159 case 'none':
160 addCSS(cssCode);
161 break;
162 case 'modified':
163 // remove the old style then add the new one
164 document.getElementsByTagName('style')[0].remove();
165 addCSS(cssCode);
166 break;
167 default:
168 // do nothing
169 }
170
171 if (pyvm) {
172 pyvm.destroy();
173 pyvm = null;
174 }
175 pyvm = rp.vmStore.init('notebook_vm');
176
177 // add some helpers for js/python code
178 window.injectPython = (ns) => {
179 for (const [k, v] of Object.entries(ns)) {
180 pyvm.addToScope(k, v);
181 }
182 };
183 window.pushNotebook = (elem) => {
184 notebook.appendChild(elem);
185 };
186 window.handlePyError = (err) => {
187 handlePythonError(error, err);
188 };
189 pyvm.setStdout((text) => {
190 const para = document.createElement('p');
191 para.appendChild(document.createTextNode(text));
192 notebook.appendChild(para);
193 });
194 for (const el of ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p']) {
195 pyvm.addToScope(el, (text) => {
196 const elem = document.createElement(el);
197 elem.appendChild(document.createTextNode(text));
198 notebook.appendChild(elem);
199 });
200 }
201 pyvm.addToScope('notebook_html', (html) => {
202 notebook.innerHTML += html;
203 });
204
205 let jsCode = buffers['js'].getValue();

Callers

nothing calls this directly

Calls 15

checkCssStatusFunction · 0.90
addCSSFunction · 0.90
handlePythonErrorFunction · 0.90
runJSFunction · 0.90
runPythonFunction · 0.90
iomdParserFunction · 0.90
renderMarkdownFunction · 0.90
renderMathFunction · 0.90
getValueMethod · 0.80
createElementMethod · 0.80
createTextNodeMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected