【发布时间】:2021-04-10 11:56:57
【问题描述】:
存在用于在 jupyter 笔记本中插入切换/隐藏代码按钮的代码(请参阅 How to hide code from cells in ipython notebook visualized with nbviewer?),并且可以在将报告从 Jupyter 导出为 HTML 时使用。
但是,此代码不再适用于 JupyterLab。似乎 JupyterLab 更改了相对于 Jupyter 的容器名称。
对于 Jupyter 容器名称是
使用这个假设,我编写了一个似乎在 JupyterLab 中工作的更新 javascript。 我在网上找不到任何类似的解决方案,而且有些网站似乎暗示出于安全原因而为 Jupyterlab 停用了 JavaScript (https://github.com/jupyterlab/jupyterlab/issues/3118#)。
我对 javascript 和 html 的理解是初级的,所以我想知道这个解决方案是否存在任何安全问题和/或重新编码的更好方法。这是我在 JupyterLab 的原始代码单元中插入的代码:
<script>
code_show="a"
var r = document.querySelector(':root')
if (code_show === "a") {
code_show="flex"
}
function code_toggle() {
var v = r.getElementsByClassName("jp-Cell-inputWrapper")
if (v.item(0).style.display === "") {
if (code_show === "none") {
for (i = 1; i < v.length-1; i++) {
v.item(i).style.display = "flex";
}
code_show = "flex"
} else {
for (i = 1; i < v.length-1; i++) {
v.item(i).style.display = "none";
}
code_show = "none"
}
}
}
</script>
<form action="javascript:code_toggle()"><input type="submit" value="TOGGLE CODE IN REPORT VIEW."></form>
【问题讨论】:
标签: javascript html security show-hide jupyter-lab