Skip to content

Commit ae23158

Browse files
committed
jupyter: revert removing redundant output reps on the server
- there should be only one given that we know the client, but this efficiency gain fights too much with what jupyter upstream expects, so we can't do this.
1 parent 65453ee commit ae23158

File tree

4 files changed

+5
-44
lines changed

4 files changed

+5
-44
lines changed

src/packages/frontend/jupyter/output-messages/mime-types/html.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export default function Html({
3939
// **backend only** text/latex and as text/html
4040
// that looks good and is meant to be rendered on the frontend.
4141
// See https://github.com/sagemathinc/cocalc/issues/5925
42+
// But Latex should have higher priority than HTML, e.g.,
43+
// sage show(...) is much better to just render using latex!
44+
// SIGH.
4245
register("text/html", 5, Html);
4346

4447
// Heuristics to only use plain stateless html.

src/packages/jupyter/ipynb/import-from-ipynb.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ Importing from an ipynb object (in-memory version of .ipynb file)
88
*/
99

1010
import * as misc from "@cocalc/util/misc";
11-
import {
12-
JUPYTER_MIMETYPES,
13-
JUPYTER_MIMETYPES_SET,
14-
} from "@cocalc/jupyter/util/misc";
11+
import { JUPYTER_MIMETYPES } from "@cocalc/jupyter/util/misc";
1512
import { type Message } from "@cocalc/jupyter/execute/output-handler";
1613
import { close } from "@cocalc/util/misc";
1714

@@ -257,7 +254,6 @@ export class IPynbImporter {
257254
if (misc.is_array(content.text)) {
258255
content.text = content.text.join("");
259256
}
260-
remove_redundant_reps(content.data); // multiple output formats
261257
delete content.prompt_number; // redundant; in some files
262258
};
263259

@@ -403,38 +399,3 @@ export class IPynbImporter {
403399
return obj;
404400
};
405401
}
406-
407-
// mutate data removing redundant reps
408-
export function remove_redundant_reps(data?: object) {
409-
if (data == null) {
410-
return;
411-
}
412-
// We only keep the first representation in types, since it provides the richest
413-
// representation in the client; there is no need for the others.
414-
// TODO: probably we should still store all of these types somewhere (in the
415-
// backend only) for the .ipynb export, but I'm not doing that right now!
416-
// This means opening and closing an ipynb file may lose information, which
417-
// no client currently cares about (?) -- maybe nbconvert does.
418-
let keep = "";
419-
for (const type of JUPYTER_MIMETYPES) {
420-
if (data[type] != null) {
421-
keep = type;
422-
break;
423-
}
424-
}
425-
if (!keep) {
426-
return;
427-
}
428-
for (const type in data) {
429-
// NOTE: we only remove multiple reps that are both in JUPYTER_MIMETYPES;
430-
// if there is another rep that is NOT in JUPYTER_MIMETYPES, then it is
431-
// not removed, e.g., application/vnd.jupyter.widget-view+json and
432-
// text/plain both are types of representation of a widget.
433-
if (
434-
type != keep &&
435-
(JUPYTER_MIMETYPES_SET as Set<string>).has(type) != null
436-
) {
437-
delete data[type];
438-
}
439-
}
440-
}

src/packages/jupyter/redux/actions.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import {
4949
JUPYTER_MIMETYPES,
5050
isJupyterBase64MimeType,
5151
} from "@cocalc/jupyter/util/misc";
52-
import { remove_redundant_reps } from "@cocalc/jupyter/ipynb/import-from-ipynb";
5352
import { isSha1, sha1 } from "@cocalc/util/misc";
5453
import { shouldUseIframe } from "@cocalc/jupyter/util/iframe";
5554

@@ -2106,8 +2105,6 @@ export class JupyterActions extends Actions<JupyterStoreState> {
21062105
return;
21072106
}
21082107

2109-
remove_redundant_reps(content.data);
2110-
21112108
// Here we compute sha1 and start saving the blob to the blob store
21122109
// over the network. There is no guarantee that will work and this
21132110
// won't just be lost. It's unlikely but could happen. This is

src/packages/jupyter/util/misc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import { cmp } from "@cocalc/util/misc";
2424
export const JUPYTER_MIMETYPES = [
2525
"application/javascript",
2626
"application/json",
27-
"text/latex",
2827
"text/html",
2928
"text/markdown",
29+
"text/latex",
3030
"image/svg+xml",
3131
"image/png",
3232
"image/jpeg",

0 commit comments

Comments
 (0)