How can I wrap top-level components in paragraph tags? #2232
-
I'm currently building a project that will contain a large amount of written dialog. For ease of use I want to write the files in markdown and have the quotes be wrapped in components to be able to consistently apply custom styles, colors, etc. This works perfectly for the first two lines of the following example, i.e. mdx wraps every every markdown paragraph with the correct import { Quote } from "~/components/dialog"
Lorem ipsum dolor sit amet, <Quote>consetetur sadipscing elitr, sed diam nonumy eirmod.</Quote>
<Quote>At vero eos et accusam et justo duo dolores et ea rebum.</Quote>, sed diam.
<Quote>Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming</Quote>
<Quote>Ut wisi enim ad minim veniam, quis nostrud</Quote> <p>
Lorem ipsum dolor sit amet, <span style="color: rgb(255, 0, 0);">"<!--#-->consetetur sadipscing elitr, sed diam nonumy eirmod.<!--/-->"</span>
</p>
<p>
<span style="color: rgb(255, 0, 0);">"<!--#-->At vero eos et accusam et justo duo dolores et ea rebum.<!--/-->"</span>, sed diam.
</p>
<span style="color: rgb(255, 0, 0);">"<!--#-->Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming<!--/-->"</span>
<span style="color: rgb(255, 0, 0);">"<!--#-->Ut wisi enim ad minim veniam, quis nostrud<!--/-->"</span> Is there a way for me to make mdx respect the markdown structure for top-level single components, i.e. wrap them in a PS: I'm currently using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is the intended behavior, you can see the past discussions on this for the reasoning https://github.com/orgs/mdx-js/discussions?discussions_q=block+inline
A few ways, without any changes to mdx you can add the paragraph JSX tags where you want them import { Quote } from "~/components/dialog"
Lorem ipsum dolor sit amet, <Quote>consetetur sadipscing elitr, sed diam nonumy eirmod.</Quote>
<Quote>At vero eos et accusam et justo duo dolores et ea rebum.</Quote>, sed diam.
<p><Quote>Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming</Quote></p>
<p><Quote>Ut wisi enim ad minim veniam, quis nostrud</Quote></p>
This may produce unexpected results, but if you really want to do this, it can be done through a plugin. If you're looking for inspiration on how another node wrapping plugin works, checkout https://github.com/jake-low/remark-sectionize which wraps headers with a section tag. |
Beta Was this translation helpful? Give feedback.
This is the intended behavior, you can see the past discussions on this for the reasoning https://github.com/orgs/mdx-js/discussions?discussions_q=block+inline
And some annotated examples in https://github.com/orgs/mdx-js/discussions/2194#discussioncomment-4357673
A few ways, without any changes to mdx you can add the paragraph JSX tags where you want them