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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: legacy image migration #975

Merged
merged 2 commits into from
Oct 1, 2024
Merged

Conversation

kellyjosephprice
Copy link
Collaborator

@kellyjosephprice kellyjosephprice commented Sep 26, 2024

PR App Ref CX-1113, CX-1114

🧰 Changes

Fixes migrating images with legacy data.

We deprecated a particular format of image magic block, but we failed to ever migrate pages away from it. They've been broken/changed for awhile, and I'm not sure if we could correctly detect the format at this point?

When they get parsed into an AST, they appear to be inline image nodes, which can then compile incorrectly. We've been treating image nodes that are alone in a paragraph as block images for awhile, so lets encode that in the migration.

🧬 QA & Testing

Copy link
Contributor

@rafegoldberg rafegoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a couple of questions on this one…

@@ -19,6 +20,12 @@ const compatibilityTransfomer = (): Transform => tree => {
return SKIP;
});

visit(tree, 'image', (node: Image, index: number, parent: Parent) => {
if (phrasing(parent) || !parent.children.every(child => child.type === 'image' || !phrasing(child))) return;
Copy link
Contributor

@rafegoldberg rafegoldberg Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, not sure I understand what would count as phrasing content? Would it match this image:

Lorem ![](/my.img) ipsum.

And does that mean we'd be treating/displaying ^said image as a block? That doesn't seem right…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also, would this image still float to the right?

Lorem ipsum:

<img align=right src=my.img />

Dolor set amos.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And does that mean we'd be treating/displaying ^said image as a block? That doesn't seem right…

We've been treating images that are alone on a line as a readme-style block level image for sometime:

## Block Image

![](my.img)

Lorem ipsum.

And also, would this image still float to the right?

Yea, that would be parsed as mdxJsxFlowElement. The image node type is usually only used for markdown images. RDMD would convert magic blocks to image nodes for simplicity. But for the reasons you're asking about, was probably a huge mistake.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, should we use this migration to convert lone markdown images to JSX, to remove the ambiguity?

Copy link
Collaborator Author

@kellyjosephprice kellyjosephprice Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And does that mean we'd be treating/displaying ^said image as a block? That doesn't seem right…

THis logic should ignore that image then. It's checking to make sure that all of the images siblings aren't phrasing. eg:

![](my.img)

## Heading

![](my-2.img)

> ![](my-3.img)
>
> - all block components

Copy link
Contributor

@rafegoldberg rafegoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tentatively approve this (though I'm still not sure I fully 100% understand how it's working/all the implications.)

__tests__/compilers/compatability.test.tsx Show resolved Hide resolved
@@ -19,6 +20,12 @@ const compatibilityTransfomer = (): Transform => tree => {
return SKIP;
});

visit(tree, 'image', (node: Image, index: number, parent: Parent) => {
if (phrasing(parent) || !parent.children.every(child => child.type === 'image' || !phrasing(child))) return;
Copy link
Contributor

@rafegoldberg rafegoldberg Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I'm understanding this thread correctly, "phrasing content" means an inline image? (I mainly ask 'cause I was noticing some issues1 with inline image editing earlier today and am wondering if this might help!)

Footnotes

  1. namely that the editor was auto-deleting all inline <Images> and ![](or.imgs)! 😬

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a link to a page?

Copy link
Contributor

@rafegoldberg rafegoldberg Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T'was just a test page on the backup DB, but essentially this:

Lorem ipsum dolor sit amet. <Image src="some.img" /> Consectetur elit neque.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, working on that in a separate PR.

Copy link
Contributor

@rafegoldberg rafegoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shit, sorry, I approved too quickly! I forgot about this question; I actually think that needs investigating/answering before we merge this.

@kellyjosephprice kellyjosephprice merged commit c900d5f into next Oct 1, 2024
13 checks passed
@kellyjosephprice kellyjosephprice deleted the fix/legacy-image-migration branch October 1, 2024 17:36
rafegoldberg pushed a commit that referenced this pull request Oct 2, 2024
## Version 7.6.5

### 🛠 Fixes & Updates

* copy button icons ([#982](#982)) ([bbe2060](bbe2060))
* fallback for 5 ([#984](#984)) ([c1ad0ac](c1ad0ac)), closes [#c50a50](https://github.com/readmeio/markdown/issues/c50a50)
* inline mdx images ([#983](#983)) ([3faa95d](3faa95d))
* legacy image migration ([#975](#975)) ([c900d5f](c900d5f))

<!--SKIP CI-->
@rafegoldberg
Copy link
Contributor

This PR was released!

🚀 Changes included in v7.6.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants