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: image compiling #960

Merged
merged 3 commits into from
Aug 29, 2024
Merged

fix: image compiling #960

merged 3 commits into from
Aug 29, 2024

Conversation

kellyjosephprice
Copy link
Collaborator

@kellyjosephprice kellyjosephprice commented Aug 29, 2024

PR App Resolves RM-10691

🧰 Changes

Fixes compiling images.

The problem was our naive transformer that could not handle non string attributes. For instance, using a false value would crash the compiler:

<Image border={false} />

This updates the toAttributes method to create the valid AST.

🧬 QA & Testing

Do the tests pass?

You could test it locally like:

npm i && npm run build
node
> const rmdx = require('./')
> rmdx.mdx(rmdx.mdast('<Image border={false} />'))

But that's roughly the same as the tests?

@kellyjosephprice kellyjosephprice marked this pull request as ready for review August 29, 2024 19:48
Comment on lines 1 to 7
import { Node } from 'mdast';
import { MdxJsxFlowElement, MdxJsxTextElement, MdxFlowExpression } from 'mdast-util-mdx';
import { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
import {
MdxJsxAttribute,
MdxJsxAttributeValueExpression,
MdxJsxAttributeValueExpressionData,
} from 'mdast-util-mdx-jsx';
Copy link
Contributor

Choose a reason for hiding this comment

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

are these imports all types? can we specify that if so?

import type { Node } from 'mdast';
import type { MdxJsxFlowElement, MdxJsxTextElement, MdxFlowExpression } from 'mdast-util-mdx';
import type {
  MdxJsxAttribute,
  MdxJsxAttributeValueExpression,
  MdxJsxAttributeValueExpressionData,
} from 'mdast-util-mdx-jsx';

Comment on lines 160 to 162
} else {
const proxy = mdast(`{${v}}`);
const data = proxy.children[0].data as MdxJsxAttributeValueExpressionData;
Copy link
Contributor

Choose a reason for hiding this comment

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

This else case is a bit hard to reason through without looking at the right test! Mind adding a comment here to clarify why/what the underlying issue is?

Suggested change
} else {
const proxy = mdast(`{${v}}`);
const data = proxy.children[0].data as MdxJsxAttributeValueExpressionData;
} else {
/* serialize <Image> components with JSX expressions in
* their attributes (i.e. [border={false}]) back to MDX.
*/
const proxy = mdast(`{${v}}`);
const data = proxy.children[0].data as MdxJsxAttributeValueExpressionData;

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.

Appreciate the quick turnaround on my review; reaffirming my approval!

@kellyjosephprice kellyjosephprice merged commit 6e3a7ac into next Aug 29, 2024
13 checks passed
@kellyjosephprice kellyjosephprice deleted the fix/image-compiling branch August 29, 2024 20:26
rafegoldberg pushed a commit that referenced this pull request Aug 29, 2024
## Version 7.4.2

### ✨ New & Improved

* **Image:** fix alignment oddities ([#956](#956)) ([7382d43](7382d43)), closes [/github.com//pull/956/files#diff-1b96290f278c30bd682c1247de2db226763c471520a387108344a9d53d13de23R19](https://github.com/readmeio//github.com/readmeio/markdown/pull/956/files/issues/diff-1b96290f278c30bd682c1247de2db226763c471520a387108344a9d53d13de23R19) [/github.com//pull/956/files#diff-19c7d495b0c7303322a8a6dcaf6813764594f9e77b9aabc2e5da9a1e274a6d92](https://github.com/readmeio//github.com/readmeio/markdown/pull/956/files/issues/diff-19c7d495b0c7303322a8a6dcaf6813764594f9e77b9aabc2e5da9a1e274a6d92)

### 🛠 Fixes & Updates

* image compiling ([#960](#960)) ([6e3a7ac](6e3a7ac))

### 📘 Tests & Docs

* update readme for MDX ([#957](#957)) ([0b5f89b](0b5f89b))

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

This PR was released!

🚀 Changes included in v7.4.2

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