From f209634643771cfd3fa7fde0db9c9d0b392f78d7 Mon Sep 17 00:00:00 2001 From: jennspencer Date: Fri, 28 Jun 2024 18:51:05 -0700 Subject: [PATCH 1/2] dialing in image/embed nodes --- components/Image/index.tsx | 70 +++++++++++++++--------------- processor/compile/compatibility.ts | 28 ++++++++---- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/components/Image/index.tsx b/components/Image/index.tsx index 3785e3bf0..a4a983893 100644 --- a/components/Image/index.tsx +++ b/components/Image/index.tsx @@ -16,7 +16,7 @@ interface ImageProps { const Image = (Props: ImageProps) => { const { - align = '', + align = 'center', alt = '', border = false, caption, @@ -25,7 +25,7 @@ const Image = (Props: ImageProps) => { src, title = '', width = 'auto', - lazy = false, + lazy = true, children, } = Props; @@ -60,55 +60,53 @@ const Image = (Props: ImageProps) => { if (caption) { return ( - - -
+
+ + {alt}
{children || caption}
-
+ - +
); } return ( -

- - - {alt} - + + + {alt} -

+
); }; diff --git a/processor/compile/compatibility.ts b/processor/compile/compatibility.ts index 69c32051f..a64c3258c 100644 --- a/processor/compile/compatibility.ts +++ b/processor/compile/compatibility.ts @@ -32,14 +32,16 @@ const html = (node: Html) => { }; const figureToImageBlock = (node: any) => { - const { align, width, src, alt, title, ...image } = node.children.find((child: Node) => child.type === 'image'); + const { align, width, src, url, alt, title, ...image } = node.children.find((child: Node) => child.type === 'image'); const { className } = image.data.hProperties; const figcaption = node.children.find((child: Node) => child.type === 'figcaption'); - const caption = figcaption ? toMarkdown({ - type: 'paragraph', - children: figcaption.children, - }).trim() : null; + const caption = figcaption + ? toMarkdown({ + type: 'paragraph', + children: figcaption.children, + }).trim() + : null; const attributes = { ...(align && { align }), @@ -48,10 +50,19 @@ const figureToImageBlock = (node: any) => { ...(caption && { caption }), ...(title && { title }), ...(width && { width }), - src, + src: src || url, }; return ``; -} +}; + +const embedToEmbedBlock = (node: any) => { + const { html, ...embed } = node.data.hProperties; + const attributes = { + ...embed, + ...(html && { html: encodeURIComponent(html) }), + }; + return ``; +}; const compatibility = (node: CompatNodes) => { switch (node.type) { @@ -68,8 +79,7 @@ const compatibility = (node: CompatNodes) => { case 'figure': return figureToImageBlock(node); case 'embed': - const attributes = formatHProps(node); - return ``; + return embedToEmbedBlock(node); default: throw new Error('Unhandled node type!'); } From 0cbf1af717b9d2dd34848a80f53303337dbc9c11 Mon Sep 17 00:00:00 2001 From: jennspencer Date: Fri, 28 Jun 2024 18:53:58 -0700 Subject: [PATCH 2/2] snaps --- __tests__/__snapshots__/index.test.js.snap | 2 +- __tests__/components/Image.test.tsx | 28 +++++++++---------- .../__snapshots__/index.test.ts.snap | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/__tests__/__snapshots__/index.test.js.snap b/__tests__/__snapshots__/index.test.js.snap index 034b28108..a7330bb0b 100644 --- a/__tests__/__snapshots__/index.test.js.snap +++ b/__tests__/__snapshots__/index.test.js.snap @@ -335,7 +335,7 @@ exports[`export multiple Markdown renderers > renders plain markdown as React 1` exports[`heading 1`] = `"

Example Header

"`; -exports[`image 1`] = `"

Image

"`; +exports[`image 1`] = `"Image"`; exports[`list items 1`] = ` "
    diff --git a/__tests__/components/Image.test.tsx b/__tests__/components/Image.test.tsx index c075e51e9..6e3f9f4a9 100644 --- a/__tests__/components/Image.test.tsx +++ b/__tests__/components/Image.test.tsx @@ -10,7 +10,7 @@ describe('Image', () => { expect(screen.getByRole('img')).toMatchInlineSnapshot(` { -
    - -
    - A pizza bro -
    -
    + +
    + A pizza bro +
    `); diff --git a/__tests__/components/__snapshots__/index.test.ts.snap b/__tests__/components/__snapshots__/index.test.ts.snap index 8bfa44ee2..110832099 100644 --- a/__tests__/components/__snapshots__/index.test.ts.snap +++ b/__tests__/components/__snapshots__/index.test.ts.snap @@ -10,4 +10,4 @@ exports[`Components > Embed 3`] = `""`; -exports[`Components > Image 1`] = `"

    Bro eats pizza and makes an OK gesture.

    "`; +exports[`Components > Image 1`] = `"Bro eats pizza and makes an OK gesture."`;