/blog/mdx-remove-unwanted-paragraph-tags #29
Replies: 2 comments
-
If you found this post helpful, please consider leaving a reaction ☝️ You're welcome to share any feedback or ask questions. All the best with your MDX journey! |
Beta Was this translation helpful? Give feedback.
0 replies
-
I just came across this issue :-(. I took another approach of unwrapping the function isP(child: React.ReactNode): child is React.ReactElement {
try {
return (
React.isValidElement(child) &&
typeof child.type !== "string" &&
child.type.name === "p"
);
} catch (e) {
return false;
}
}
export function Description({ children }: React.PropsWithChildren<{}>) {
// We extract the first child. If it's a <p> tag, we take its content.
const [firstChild, ...rest] = React.Children.map(children, (child, i) => {
return i === 0 && isP(child) ? child.props.children : child;
});
return (
<div className="nx-w-full nx-min-w-0 nx-leading-7">
<p className="nx-mt-6 nx-leading-7 first:nx-mt-0">
<strong>Example. </strong>
{firstChild}
</p>
{rest}
</div>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
/blog/mdx-remove-unwanted-paragraph-tags
Prevent invalid HTML markup by eliminating extra
tags in your multi-line JSX elements. Learn how to fully leveraging the power of MDX and JSX.
http://localhost:3000/blog/mdx-remove-unwanted-paragraph-tags
Beta Was this translation helpful? Give feedback.
All reactions