Skip to content

Commit 9c4c92d

Browse files
committed
jupyter iframe heuristic - make it a little less specific to particular library
1 parent 04eb751 commit 9c4c92d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/packages/jupyter/blobs/iframe.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ import { decode } from "he";
1717
// - if it starts with iframe
1818
// - if it has a whole page doctype
1919
// - if it has a <script> tag anywhere without a type -- since those are ignored by safe HTML
20-
// rendering; using an iframe is the only way. This e.g., makes mpld3 work! https://github.com/sagemathinc/cocalc/issues/1934
20+
// rendering; using an iframe is the only way. This e.g., makes mpld3 work uses -- <script>! https://github.com/sagemathinc/cocalc/issues/1934
21+
// and altair -- https://github.com/sagemathinc/cocalc/issues/4468 -- uses <script type="text/javascript"/>
22+
// - do NOT just render all html in an iframe, e.g., this would break bokeh, since one output creates the target elt,
23+
// and a different output uses javascript to render it, and this doesn't work with an iframe, of course.
2124
export function is_likely_iframe(content: string): boolean {
2225
if (!content) {
2326
return false;
2427
}
25-
content = content.slice(0, 100).trim().toLowerCase();
28+
content = content.toLowerCase();
2629
return (
30+
content.includes("bk-notebook-logo") ||
2731
content.startsWith("<iframe") ||
2832
content.includes("<!doctype html>") ||
2933
(content.includes("<html>") && content.includes("<head>")) ||
30-
// special case "altair" inline html -- https://github.com/sagemathinc/cocalc/issues/4468
31-
content.includes('id="altair-viz-') ||
32-
content.includes("<script>")
34+
content.includes("<script>") ||
35+
content.includes('<script type="text/javascript">')
3336
);
3437
}
3538

0 commit comments

Comments
 (0)