From 9c2344afd9f3314f8b2ca389f58dca9e3f2e2973 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 25 Feb 2026 02:52:29 +0100 Subject: [PATCH] fix: render markdown links as tags and convert newlines to
in Lexical text nodes --- components/PayloadRichText.tsx | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/components/PayloadRichText.tsx b/components/PayloadRichText.tsx index 9e4dabb8..70f50e4b 100644 --- a/components/PayloadRichText.tsx +++ b/components/PayloadRichText.tsx @@ -45,6 +45,52 @@ const jsxConverters: JSXConverters = { ); } + // Handle markdown-style links [text](url) from MDX migration + if (text && /\[([^\]]+)\]\(([^)]+)\)/.test(text)) { + const parts: React.ReactNode[] = []; + const remaining = text; + let key = 0; + const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g; + let match; + let lastIndex = 0; + while ((match = linkRegex.exec(remaining)) !== null) { + if (match.index > lastIndex) { + parts.push({remaining.slice(lastIndex, match.index)}); + } + parts.push( +
+ {match[1]} + , + ); + lastIndex = match.index + match[0].length; + } + if (lastIndex < remaining.length) { + parts.push({remaining.slice(lastIndex)}); + } + return <>{parts}; + } + + // Handle newlines in text nodes — convert to
for proper line breaks + if (text && text.includes('\n')) { + const lines = text.split('\n'); + return ( + <> + {lines.map((line: string, i: number) => ( + + {line} + {i < lines.length - 1 &&
} +
+ ))} + + ); + } + if (node.format === 1) return {text}; if (node.format === 2) return {text}; return {text};