Skip to content

Commit

Permalink
🏞 Fix placeholders when outputs are empty (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves authored Jul 17, 2023
1 parent 88aa318 commit 0b36379
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-mice-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@myst-theme/jupyter': patch
---

Placeholders are now displayed in figures that embed notebook cells with empty outputs
8 changes: 8 additions & 0 deletions packages/jupyter/src/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { SafeOutputs } from './safe';
import { JupyterOutputs } from './jupyter';
import { useMemo } from 'react';
import { useCellExecution } from './execute';
import { usePlaceholder } from './decoration';
import { MyST } from 'myst-to-react';

export const DIRECT_OUTPUT_TYPES = new Set(['stream', 'error']);

Expand Down Expand Up @@ -51,9 +53,15 @@ export function JupyterOutput({
() => allOutputsAreSafe(outputs, DIRECT_OUTPUT_TYPES, DIRECT_MIME_TYPES),
[outputs],
);
const placeholder = usePlaceholder();

let component;
if (allSafe && !ready) {
if (placeholder && (!outputs || outputs.length === 0)) {
if (placeholder) {
return <MyST ast={placeholder} />;
}
}
component = <SafeOutputs keyStub={outputId} outputs={outputs} />;
} else {
component = <JupyterOutputs id={outputId} outputs={outputs} />;
Expand Down

0 comments on commit 0b36379

Please sign in to comment.