-
-
Notifications
You must be signed in to change notification settings - Fork 5
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 |
If anyone is interested, or someone is having a similar problem, as a reference, I wrote a simple plugin to solve it. https://github.com/cangSDARM/remark-drop-paragraph You can find a sample in https://github.com/cangSDARM/blog (next14), especially |
please don’t do this in remark :'( |
I think that remark deals with the whole syntax tree, while rehype deals with the attributes of a node. So I wrote it in remark 🤔 |
it doesn’t :'( You deal with html. |
noted. I'll see if I can change it when I have time 👍🏻 |
No worries, it’s common! Some more info here: https://github.com/remarkjs/remark-rehype#what-is-this! |
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: