Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃巻 Support inline property on image nodes #248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-frogs-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-react': patch
---

Support inline property on image nodes
14 changes: 13 additions & 1 deletion packages/myst-to-react/src/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,33 @@ function alignToMargin(align: string) {
}
}

function inlineStyle(inline?: boolean) {
if (inline) return { display: 'inline' };
return {};
}

function Video({
src,
urlSource,
align = 'center',
width,
height,
inline,
}: {
src: string;
urlSource?: string;
width?: string;
height?: string;
align?: Alignment;
inline?: boolean;
}) {
return (
<video
style={{
width: getStyleValue(width),
height: getStyleValue(height),
...alignToMargin(align),
...inlineStyle(inline),
}}
src={src}
data-canonical-url={urlSource}
Expand All @@ -77,6 +85,7 @@ function Picture({
alt,
width,
height,
inline,
}: {
src: string;
srcOptimized?: string;
Expand All @@ -85,6 +94,7 @@ function Picture({
width?: string;
height?: string;
align?: Alignment;
inline?: boolean;
}) {
if (src.endsWith('.mp4')) {
return <Video width={width} height={height} align={align} src={src} urlSource={urlSource} />;
Expand All @@ -95,6 +105,7 @@ function Picture({
width: getStyleValue(width),
height: getStyleValue(height),
...alignToMargin(align),
...inlineStyle(inline),
}}
src={src}
alt={alt}
Expand All @@ -103,7 +114,7 @@ function Picture({
);
if (!srcOptimized) return image;
return (
<picture>
<picture style={{ ...inlineStyle(inline) }}>
<source srcSet={srcOptimized} type="image/webp" />
{image}
</picture>
Expand All @@ -119,6 +130,7 @@ export const Image: NodeRenderer<ImageNode> = ({ node }) => {
width={node.width || undefined}
height={node.height || undefined}
align={node.align}
inline={node.inline}
// Note that sourceUrl is for backwards compatibility
urlSource={(node as any).urlSource || (node as any).sourceUrl}
/>
Expand Down