Skip to content

Commit

Permalink
🌉 Minor improvements for handling subfigures
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Nov 22, 2023
1 parent 9f44076 commit a47f237
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/strong-masks-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'myst-to-react': patch
'@myst-theme/jupyter': patch
'@myst-theme/styles': patch
---

Improve handling for subfigures
22 changes: 14 additions & 8 deletions packages/jupyter/src/figure.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SourceFileKind } from 'myst-spec-ext';
import { type GenericNode } from 'myst-common';
import { DEFAULT_RENDERERS, MyST } from 'myst-to-react';
import classNames from 'classnames';
import { OutputDecoration } from './decoration.js';

export function Figure({ node }: { node: GenericNode }) {
Expand All @@ -11,15 +12,20 @@ export function Figure({ node }: { node: GenericNode }) {
const placeholder = node.children?.find((child) => child.type === 'image' && child.placeholder);
const others = node.children?.filter((child) => !(child.type === 'image' && child.placeholder));
return (
<OutputDecoration
key={node.key}
outputId={output.id}
placeholder={placeholder}
title={node.source?.title}
url={node.source?.url}
<figure
id={node.html_id || node.identifier || node.key}
className={classNames({ subcontainer: node.subcontainer }, node.class)}
>
<MyST ast={others} />
</OutputDecoration>
<OutputDecoration
key={node.key}
outputId={output.id}
placeholder={placeholder}
title={node.source?.title}
url={node.source?.url}
>
<MyST ast={others} />
</OutputDecoration>
</figure>
);
}
return <Container node={node} />;
Expand Down
5 changes: 4 additions & 1 deletion packages/myst-to-react/src/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ const BASIC_RENDERERS: BasicNodeRenderers = {
},
container({ node }) {
return (
<figure id={node.html_id || node.identifier || node.key} className={classNames(node.class)}>
<figure
id={node.html_id || node.identifier || node.key}
className={classNames({ subcontainer: node.subcontainer }, node.class)}
>
<MyST ast={node.children} />
</figure>
);
Expand Down
7 changes: 7 additions & 0 deletions styles/figures.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ figure.quote figcaption > p:before {
figure.code > div {
margin: 0;
}
figure.subcontainer {
margin-bottom: 0;
}
figure.subcontainer figcaption {
margin-top: 0.25em;
text-align: center;
}
figure figcaption > p {
margin-top: 0 !important;
margin-bottom: 0 !important;
Expand Down

0 comments on commit a47f237

Please sign in to comment.