diff --git a/components/JsonToHtml/renderOptions.tsx b/components/JsonToHtml/renderOptions.tsx
index 219981529..2ce1afbec 100644
--- a/components/JsonToHtml/renderOptions.tsx
+++ b/components/JsonToHtml/renderOptions.tsx
@@ -42,6 +42,17 @@ import type {
import { RTEMarkType } from "@/types/transitionTypes/rte/node"
import type { RenderOptions } from "@/types/transitionTypes/rte/option"
+function noNestedLinksOrReferences(node: RTENode) {
+ if ("type" in node) {
+ if (node.type === RTETypeEnum.reference) {
+ return node.children
+ } else if (node.type === RTETypeEnum.a) {
+ return node.children
+ }
+ }
+ return node
+}
+
function extractPossibleAttributes(attrs: Attributes | undefined) {
if (!attrs) return {}
const props: Record = {}
@@ -82,7 +93,13 @@ export const renderOptions: RenderOptions = {
variant="underscored"
color="burgundy"
>
- {next(node.children, embeds, fullRenderOptions)}
+ {next(
+ // Sometimes editors happen to nest a reference inside a link and vice versa.
+ // In that case use the outermost link, i.e. ignore nested links.
+ node.children.flatMap(noNestedLinksOrReferences),
+ embeds,
+ fullRenderOptions
+ )}
)
}
@@ -340,28 +357,22 @@ export const renderOptions: RenderOptions = {
) {
// If entry is not an ImageContainer, it is a page and we return it as a link
const props = extractPossibleAttributes(node.attrs)
- let href = ""
- if (entry?.node.__typename === ContentEnum.blocks.AccountPage) {
- href = removeMultipleSlashes(
- `/${entry.node.system.locale}${entry.node.url}`
- )
- } else {
- href =
- entry.node?.web?.original_url ||
- removeMultipleSlashes(
- `/${entry.node.system.locale}${entry.node.url}`
- )
- }
return (
- {next(node.children, embeds, fullRenderOptions)}
+ {next(
+ // Sometimes editors happen to nest a reference inside a link and vice versa.
+ // In that case use the outermost link, i.e. ignore nested links.
+ node.children.flatMap(noNestedLinksOrReferences),
+ embeds,
+ fullRenderOptions
+ )}
)
}