Skip to content

Commit 04eb751

Browse files
committed
jupyter: render any html with <script> using iframe automatically; this makes it mpld3 works
1 parent 7613271 commit 04eb751

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/packages/jupyter/blobs/iframe.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import { decode } from "he";
1313
//import { getLogger } from "@cocalc/backend/logger";
1414
//const logger = getLogger("jupyter:blobs:iframe");
1515

16+
// We use iframes to render html in a number of cases:
17+
// - if it starts with iframe
18+
// - if it has a whole page doctype
19+
// - 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
1621
export function is_likely_iframe(content: string): boolean {
1722
if (!content) {
1823
return false;
@@ -23,7 +28,8 @@ export function is_likely_iframe(content: string): boolean {
2328
content.includes("<!doctype html>") ||
2429
(content.includes("<html>") && content.includes("<head>")) ||
2530
// special case "altair" inline html -- https://github.com/sagemathinc/cocalc/issues/4468
26-
content.includes('id="altair-viz-')
31+
content.includes('id="altair-viz-') ||
32+
content.includes("<script>")
2733
);
2834
}
2935

0 commit comments

Comments
 (0)