我正在使用 IPython Notebook markdown 创建一个文档,它确实允许一些 HTML,例如<img>
例如但我添加了<object>
包含 SVG 文件,但它不会显示在 IPython Notebook 输出中。我仔细检查了 IPython Notebook 的 HTML 源代码和<object>
IPython Notebook 服务器不提供标记。看起来像<iframe>
标签也经过消毒。
然而,当我自己在 IPython Notebook 之外将其转换为 HTML 文件时,它工作得很好。我需要做些什么来添加吗<object>
and <iframe>
到允许的 HTML 标签列表?
我找到了 Jupyter 的安全.js https://github.com/jupyter/notebook/blob/666ecbf35c3310335a3c8c182e8f53441c991c14/notebook/static/base/js/security.js#L79但不确定它是在服务器还是客户端上运行,也不知道如何更改它。
我也尝试过“文件”→“信任笔记本”,但这也没有解决问题。
我对 site-packages/notebook/static/notebook/js/main.min.js 的本地副本进行了猴子修补,使其具有以下内容:
var sanitize_html = function (html, allow_css) {
/**
* sanitize HTML
* if allow_css is true (default: false), CSS is sanitized as well.
* otherwise, CSS elements and attributes are simply removed.
*/
var html4 = caja.html4;
if (allow_css) {
// allow sanitization of style tags,
// not just scrubbing
html4.ELEMENTS.style &= ~html4.eflags.UNSAFE;
html4.ATTRIBS.style = html4.atype.STYLE;
} else {
// scrub all CSS
html4.ELEMENTS.style |= html4.eflags.UNSAFE;
html4.ATTRIBS.style = html4.atype.SCRIPT;
}
/* BEGIN NEW CODE */
var whitelist_key = html.match(/<span class="whitelist:([0-9A-Za-z-_]+)"\s+\/?>/)
if (whitelist_key && whitelist_key[1]== /* password goes here */)
{
console.log("whitelist ok");
html4.ELEMENTS.object &= ~html4.eflags.UNSAFE;
html4.ATTRIBS['iframe::src'] = 0;
html4.ATTRIBS['object::data'] = 0;
html4.ATTRIBS['object::type'] = 0;
}
/* END NEW CODE */
然后在我的笔记本的单元格中添加<span class="whitelist:mypassword" />
目前可以用,我已经打开了问题#2614 https://github.com/jupyter/notebook/issues/2614在 github 上。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)