-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Unwrap figure elements #11
Comments
Please spend more time framing your question. It is unclear what you want. See https://github.com/remarkjs/.github/blob/main/support.md#asking-quality-questions |
This comment has been minimized.
This comment has been minimized.
Sorry, I've improved my explanation of the problem. Does that make sense? |
How?
Please share the MDX file you have and share the errors you see. |
It's a custom implementation - I am passing a custom implementation of the import Picture from "./components/Picture";
export const MDXComponentsMap = {
img: Picture,
... // omitted for the sake of brevity
}
// "components/Picture"
const Picture = ({ src, alt = "", title, className }: Props): JSX.Element => (
<StyledFigure className={className}>
<img src={src} alt={alt} />
{title && <figcaption>{title}</figcaption>}
</StyledFigure>
); Then in my MDX, I do something like this: <img src"..." title="Caption" /> And the output is: <p>
<figure>
<img src"..." />
<figcaption>Caption</figcaption>
</figure>
</p> While the desired output should look like this: <figure>
<img src"..." />
<figcaption>Caption</figcaption>
</figure> Does that make sense? |
You don’t need anything. This plugin already does what you want. This plugin works on the markdown/MDX AST. |
This comment has been minimized.
This comment has been minimized.
Actually, it works for me and my use case and I believe it will also work for others too. else if (
child.type === 'image' ||
child.type === 'figure' || // This
child.type === 'imageReference'
) |
There is no mdast node of type |
Initial checklist
Problem
I have a NextJS app, which makes use of MDX.
The images rendered in that app are wrapped in
figure
element. By default, these elements are wrapped in a paragraph. Since,figure
is closely related toimg
, I thought we could add support forfigure
elements also here, because this package solves the same issue.When rendering figure elements in MDX, they're wrapped in a paragraph producing hydration errors (NextJS).
Solution
Simply unwrap also figure elements.
Alternatives
I cannot think of any.
The text was updated successfully, but these errors were encountered: