Parsing links in markdown and use next/link #17088
-
Hi there, first off, I love Next.js. This is a pleasure to code in. So i have a question about links that come through from our CMS. Our WYSIWYG produces markdown, and if the markdown contains a link, how do we parse the link and wrap in the So what i've tried so far is to parse the markdown with Here's the example of markdown
Render component
Does anyone has suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
You can define a renderers object as a ReactMarkdown prop, which should give you a little more control over the link: <ReactMarkdown
renderers={{
link: ({ children, href }) => {
return <Link href={href}><a>{children}</a></Link>
}
}}
/> Edited to fix the example code |
Beta Was this translation helpful? Give feedback.
-
buenas en mi caso no me veo que next/link salga y uso este codigo |
Beta Was this translation helpful? Give feedback.
-
Can this be done with a slug of HTML as well? I have an external CMS system where the markup is HTML. I am looking to use both the Nextjs link tag for hrefs and image tag (for img). |
Beta Was this translation helpful? Give feedback.
-
I've come through the same problem, and since ReactMarkdown has no
|
Beta Was this translation helpful? Give feedback.
-
With Next.js 14, I utilized the following approach due to the limitations of using the HTML tag element within the Link component and TypeScript type issues. This allows me to navigate to the desired link within the site without triggering a full re-render.
Usage:
|
Beta Was this translation helpful? Give feedback.
You can define a renderers object as a ReactMarkdown prop, which should give you a little more control over the link:
Edited to fix the example code